Round 1: (1hr)
Q1. Snakes and humans - He had modified the questions to land, human, snakes and how much time does it take for all humans to get poisioned
Similar to Rotting Organges - https://leetcode.com/problems/rotting-oranges/
I had told the approach and implemented code from this one and he was satisfied that.
Q2. Check if 2 nodes are cousins in a binary tree- https://leetcode.com/problems/cousins-in-binary-tree/
For second one I didn't get time so I had only explained the approach and he was fine with that.
Round 2: (1hr)
Q1.
/**
*
* Amazon
* Programs -> Pantry, Fresh, PrimeNow -> M such programs
* Sellers subscribe to programs
*
* Bananas
* Pantry -> [5, 12, 13, 15, ...] - N length
* Fresh -> [7, 8 ,9 , ..]
* .
* .
* .
*
* End customer -> [5, 5, 8, 9, 12, 13, 15, ...]
*
* */There are different sellers(M) in different programs and for a sigle product(banana) they are selling with different prices, your task is to mention the prices of banans in a sorted list to the end customer.
Merge k sorted lists - https://leetcode.com/problems/merge-k-sorted-lists/
I had mentioned Divide and Conquer approach and then second approach with (m*n) heap size, after he asked me to optimze, used heap of size m and coded the algorigthm.
Utill now, it was going well.. and he was fine with the code. 40-45 mins elapsed.
Q2.
/**
*
*
*
* Problem 2:
Given a number of friends who have to give or take some amount of money from one another.
Design an algorithm by which the total cash flow among all the friends is minimized.
Let say 3 friends are there:
P0 has to pay 2000 Rs to P1
P0 also has to pay 4000 Rs to P2
P1 has to pay 10000 Rs to P2
*/Optimal Account Balancing - https://leetcode.com/problems/optimal-account-balancing/
I told that we can first create a map with person id -> balance (-ve if in debt and +ve if he gains money) then I mentioned that to minimize the transactions we can use 2 heaps(minimum, maximum) one to check maximum debt person and other to person who gains maximum money. I took around 20min to come up with this idea.
We pop out the top elements in both the heaps and make a transaction, if the result is a debt put the result in min_heap, else if result is gain put in max_heap. Every time we pop out the elements count the transations.
He aggred with this approach and told that code is not required as he already checked the code in first question. At this point we are 15min past to the scheduled end-time.
Final result -> REJECTED
Later I checked that we can't solve the Q2 with 2 heaps and we have to use another approach.
Any feedback is appreaticated!