Hi LC friends, I just received an offer from Amazon for a SDE1 position. I want to help one another by sharing my experience, feel free to ask me any question.
Amazon Fresh Deliveries
Given allLocations list of co-ordinates (x,y) you have to find the X - closest locations from truck's location which is (0,0). Distance is calculated using formula (x^2 + y^2). If the there is tie then choose the co-ordinate with least x value. Output list can be in any order.
Sample Input :
allLocations :
[ [1, 2] , [1, -1], [3, 4] ]
numOfDeliveries :
2Sample Output :
[ [1, -1], [1, 2] ]Solution:
This question was basically to find the K closest points to the origin (0,0) and with addtional conditions to break the tie, solved by using a heap.
Demolition Robot
Given a matrix with values 0 (trenches) , 1 (flat) , and 9 (obstacle) you have to find minimum distance to reach 9 (obstacle). If not possible then return -1.
The demolition robot must start at the top left corner of the matrix, which is always flat, and can move on block up, down, right, left.
The demolition robot cannot enter 0 trenches and cannot leave the matrix.
Sample Input :
[1, 0, 0],
[1, 0, 0],
[1, 9, 1]]Sample Output :
3Solution:
Solved by using BFS, made modifications on the given map to use it as a cache, otherwise the time limit will be reached.
4 rounds of mix behaviour and coding questions on the same day. (Recruiter told me that only three rounds will contain coding questions and it was clearly not what happened LOL.)
Friends and Posts and find the most K popular tags from posts amoung all friends.