Round 1:
Client: Dish, Vodaphone
Question 1:
/* Input in json format is given as below:
[
{
"id":"P1",
"dependency":[
"P2",
"P3"
]
},
{
"id":"P2",
"dependency":[
"P3"
]
},
{
"id":"P3",
"dependency":[
]
},
{
"id":"P4",
"dependency":[
]
},
{
"id":"P5",
"dependency":[
"P6"
]
},
{
"id":"P6",
"dependency":[
]
}
output: is to return process array in reverse order. i.e process which doesnot has any dependency to first process
i.e [P6, P5], [P4], [P3, P2, P1], [P3, P1]
] */
I tried solving the same using Dfs first as below:
//recursion
static void dfs (Node n) {
if(n.visited && n.dependencies == null) {
resp.add(n);
}
while(!n.visited) {
char[] d = n.getDepencies();
for (char c : d) {
dfs(new Node(d));
}
}
}
but was facing problem of parallel processing. Hence went ahead with another solution.
class Node {
int id;
char[] dependencies;
boolean visited;
}
Node[] resp = null;
static void processPrint(JsonArray arr) {
Map<String> mp = new HashMap<>();
int it = 1;
char[] depArr = arr.getdependency();
char[] p = null;
For(String depe : depArr) {
int j=0;
while(depe.getId() != null) {
String id = depe.getId();
while(depArr.contains(id)) {
p[j++] = id;
mp.put(it++, p);
}
}
}
for (Node node : n) {
//char[] c = n.getdependencies();
//mp.put(n.getId(), c.size());
if(!node.visited) {
dfs(node);
}
}
}Question 2:
Given an input:
InitCOunt = waterBottle, 9,
exchangeValue = empty, 3
For each exchange count, you can add one more bottle. So get me total count of bottle for each initCount value.
Here ouput: count = 13
You can can 3 extra bottle on 9/3. again 3 exchangevalue so even on extra bottle, you will get one more bottle. So 9+4 = 13I found it pretty simple and could solve it in 10 min. Exact and correct solution is:
static void getCount(int initCount, int excVal) {
int div = initCount/excVal; //7/4 = 1
int rem = initCount % excVal; // 7%4 = 3
int extrBott = 1;
extrBott = extrBott * div; //ext = 1
initCount = initCount + extrBott;
if(extrBott >= excVal) {
extrBott++;
}
return initCount;
}
Round 2:
Questionn 1:
Give me name of API required for below functionality:
- onboard a new restaurant
- User: management
- booking table itself
My Answer:
1) user-api
user: id, emailId, name, cell, role
Methods: add user, update User, management, normal: request_rest, add review
2) payment-api
card, date_of_bill, amount, response
3) restaurant-api
restaurant: id, name, location, review, no_of_users, type table
Methods: add New Restaurant, update rest data, delete - soft delete
For ex:
/*
{
"restaurants":
{
"id": "1",
"name": "Seasin Tea Loinge",
"location": "sfjke",
"review": {
"rating": "4",
"positive": "50%"
}
}
}
*/
4) Review-api (As review happens on large scale. For example Amazon review)
review Id, by, date
methods: calculate_Avg_review, AddReview, fetchReview, UpdateRating
5) Web app (Api gateway), for multitenant(client) onboarding
client : "season lounge", "Ravindra hotel"
Question 2:
Input String:
str 1: Bananaa,
str 2: na
Output: 5
Input 2:
str 1: Bananaa,
str 2: naa
Outout2: 6
Here you have to return count of how many times Str2 can be formed inside Str1.
So output will be 5. 5 pair of "na" can be formed here.My approach trial:
static booleann subSequence(String s1, String s2) {
int n = s1.length();
Stack<Character> stk = new stack<>();
Map<Character> mp = new HashMap<>();
int count = 1;
int j=0;
char[] c = s1.toCharArray();
for (char s : c) {
char firtChar = s2[j++];
boolean go = false;
if(s == firtChar && !go) {
go = true;
} else if(go && s == firstChar && s1.contains(s2)) {
count++;
}
while(j<s2.size()) {
if(go) {
count += (s == s2[j++]) ? 1 : 0;
}
}
}
/*for(int i=0;i < n-1; i++) {
if(s2[j++] == s1[i]) {
stk.add(s1[i]);
}
if(s2[j] == s1[i] && s2[j-1] == stk.peek()) {
count++;
}
}
while(s1.contains(s2)) {
count++;
s1.remove(s2);
}
}*/
return count;
}