VMware | MST4 | Senior Lead Software Engineer | All Rounds (Team 3)

Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2021-03-16Added By Anonymous
Source: Link

Company: VMware
Role: Senior Lead Software Engineer (MST4)
Interview Stage: Onsite
Location: unknown
Year: unknown

Original Post Content:

Round 1:
- Tell me about yourself
- What are the things you need to take care of while designing microservices - loose coupling, single responsibility
- Why do you think we need microservices
- Managing monolithic service is difficult, what challenges do you think can come if we opt for microservices
- What is single responsibility
- Benefits of GitLab over Jenkins pipeline, as Jenkins has many new features deployed recently
- How can you make microservices to interact with each other (Ans: REST calls)

How to achieve asynchronous behavior - eg: 2 users trying to book tickets in a cinema and request at the same time, how will you manage(Don't use synchronized). I told them another approach called SQS.
He asked except SQS how can you achieve it across multiple REST? (Mostly Saga is the answer)

How to handle multi-microservice based scenario with multiple functionality in one request - on booking.com if a user selects flight and hotel at the same time, what if flight booking is successful and hotel fails, user multiple microservice and how will you handle this behavior (saga)
Ans: Flight microservice 1 is SU, DB entry stored with status in it, go to Hotel microservice, if it fails then come back to Flight and cancel it and update DB status too.

Microservice level duplicate how will you handle - Eg: If customer1 sends a request to buy a fund, backend processing is done but response not received, meanwhile network issues shut down your machine (Maybe local issue or server crashes), customer1 comes back and places the same request again. Now request is different to the app, how will you prevent such a scenario?
Ans: You definitely will have a DB entry with, say, fund name, amount and customer id. For every request, check for combination of this 3 fields in DB in last say 1 hour. If you find entry having same amount, same fund and custid, it can be this scenario. Return message saying "Duplicate request found, please try again."
He said: there is a term for handling this duplicate. what is that.
I: I don't know.

What is saga

Round 2:

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.lang.*;


//Input:
/**

Design your own logger api. Where you need to print the request Id based on Start time sorting order.
For example here request 2 start first but end at 4 but req1 starts late at 3 and end early at 3.30. Here output should be based on startTime sorting order and request those ended before other request should be printed immediately. Here Request2 will be printed first at 4PM and Request1 was in queue since it ended at 3.30 so should be printed immediately once request2 gets printed.

Id startTime endTime
req1 3 oclock 3.30 oclock
req2 2 oclock 4 pm
*/

Code:

public class Logger {

//O(log n)
public Map<String, String> tm = new TreeMap<>();

//approach 2:
public Stack<String> s= new Stack<>();

// req -

// public Map<Long, Object> tm1 = new TreeMap<>();
public void startEvent(String reqId, long sTime ){

tm.put(sTime, reqId); //o(log N);

/*List<Map.Entry<String, String>> list = new LinkedList<Map.Entry<String, String>>(tm.entrySet());
Collections.sort(list, new Comparator<Map.Entry<String, String>>() { // N log(n)
public int compare(Map.Entry<String, String> o1,
Map.Entry<String, String> o2) {
return o1.getValue().compareTo(o2.getValue());

}
});*/
}

public void endEvent(String reqId, long endTime){

//tm: req2, req1
Queue<String> q = new Queue();
for(int i: tm){
q.put(tm.get(i)+"-"+i);
//[q.get(0) == req2-2, q.get(1 == req1-3]
}

String value = tm.get(reqId);
value = value + "-" + endTime;
tm.put(reqId, value);

long now = LocalDateTime.now();
if(now == endTime) //get current time
if(q.peek().split("-").get(0) == reqId)
//if(tm.get(0).reqId == reqId)
System.out.print("Request:: "+reqId + " Start Time::"+tm.get(reqId)+ " End time:: "+endTime);
// iterator over queue
/*for(Map.Entry<String, String> a: tm.entrySet()) {
String[] s = a.getValue().split("-"); // s=[startTime EndTime]
if(s!= null) {
if((Long.parseLong(s[1])) < now) {
System.out.print("Request:: "+reqId + " Start Time::"+tm.get(reqId)+ " End time:: "+endTime);
}
}

}*/
}

}

public static void main(String[] args) {
// req Id - 123 start time - <> end time - <>
startEvent("Req1", 2);
endEvent("Req1", 4);
startEvent("Req2", 3);
endEvent("Req2", 3);
}
}

Round 3:

Return subsequent subarray having great sum.
For example: arr = [3,-1,0,-4, 6, -1, 2]. Total sum = 5.
Output: [6,-1, 2]. sum = 7. // Here total sum is greater than sum of entire array

Solution: step1: Calculate sum of elements one by one.
// elem sum
//3 3
//-1 2
//0 2
//-4 -2
//6 4
//-1 3
//2 5

step 2: break the array of -negative sum is found and keep moving forward

Question 2:

Design a shopping cart and calculate total prize including discounts company has to offer.
For example: Have a look at below diagram in image which have multiple level of discounts. Initially I had suggested different tables like boys, girls etc. But can be solved with Category table only

(Refer to image for discount diagram: https://assets.leetcode.com/users/images/fea3a89a-58f8-4466-8740-e0b9398a0278_1615899276.0208507.jpeg)

category:
id . . category . . parent Id . . discount
1 . c1 . . 2 . . 10
2 . . c2 . . 3 . . 3
3 . . c3 . .
4 . . c4
5. c5 . . 1 . .

0+10+3 + 0 =13%

Comments