(Easy)Machine Coding: Parking lot implementation. There could be 3 gates. Multiple vehicles could be entering at the same time as well as exiting at the same time. Implement without any race conditions.
Bonus: Custom priority for parking spot.
Further there was a lot of cross questioning on the approach like how to optimize the synchronised block, how to handle inconsistencies etc.
Problem Solving:
Q1: (Medium) Given an ongoing stream of events. Return the count of out-of-order events in real time corresponding to each order.
Correct order: Approved -> RTS -> shipped -> delivered
Message structure: {“order_id” : “1”, “event”: RTS}
Assume the input would be a fixed size array of the above-described message structure. There would be a sliding window of fixed size. You need to print the out-of-order events only for the current snapshots of the window.
For ex:
[{“order_id” : “1”, “event”: RTS}, {“order_id” : “2”, “event”: Approved}, {“order_id” : “1”, “event”: Delivered}]
window size: 3
Output: 0
[{“order_id” : “1”, “event”: Delivered}, {“order_id” : “2”, “event”: Approved}, {“order_id” : “1”, “event”: RTS}]
window size: 3
Output: 1
[{“order_id” : “1”, “event”: Delivered}, {“order_id” : “2”, “event”: Approved}, {“order_id” : “1”, “event”: RTS}, {“order_id” : “1”, “event”: Shipped}]
window size: 3
Output: 1 0
Description: The first window sees order number 1 is delivered proceeded by order number 1 get RTS(which is out of sequence) hence error count 1. The next window slide sees order number 1 receives RTS and then order number 1 receives Shipped. Which is the correct sequence, hence the error count goes back to 0.
Q.2: Given a data of previously done auctions. Auctions take place every one hour. You may buy and sell the item at any hour seeing from the data (within 24 hours). How to maximize the profit.
1 : 10
2: 30
.
.
.
24: 32
Q.3: Given a list of processes. There could be only one kernel process. How would you identify the kernel process given a function such that
identifyParent(P1, P2) : returns true if P1 is parent of P2, else returns false.
Design a cab booking system like uber.
Managerial: Discussed about the current team, work which I'm doing. Motivation behind joinining Flipkart.