Amazon | OA Feb 28 2021| SDE 2 | Robot Bounded & Optimizing Box Weights
Anonymous User
15836

2 questions - complete the implementation + explain your apprach + mention time and space complexity in a total of 105 minutes.
Question 1: https://leetcode.com/discuss/interview-question/1021441/Amazon-OA-or-optimizating-Box-Weight
Question 2: https://leetcode.com/problems/robot-bounded-in-circle/

Q1: Couldn't pass all cases for Q1 by sorting the array and then trying to get the elements in set A in one pass. 2 cases failed which I suspect is because of duplicates in the array (interesction of two sets should be empty).
So I attempted to convert the problem into a knapsack problem and tried to get the elements in set B (with an upper weight limit set to ((total weight)/2 -1). Then get the remaining elements in Set A. Wasted a lot of time trying to do it in a bottom up dp table approach.
Basically something like this:
if (weighti > j) dp[i][j] = 0
else dp[i][j] = Math.max(dp[i-1][j], (freq of weighti) + dp[i-1][j-weighti])
Couldn't get it working on time. Reverted to the first approach and submitted (with 2 cases failing).

Q2: Passed all cases

Update: Passed assesment, phone screen has been scheduled

Comments (10)