Amazon SDE 1 - OA2
Anonymous User
5144
Year of experience0 (just graduated)
RoleSDE 1
PlaceEurope
Verdictpass to next round

I have been contacted by an Amazon recruiter on Linkedin asking about my resume, after small talks I received OA 2 by email. I had one week to complete it. I took the first 5 days to brush up my skills and did it.

Question one

Given an array representing the locations of N restaurants in the city, implement an algorithm to find the nearest X restaurants to the customer's location.
The customer begins at the location [0, 0].
Return a list of elements where each element of the list represents the x and y inter coordinates of the nearest recommanded restaurants.
numRestaurants <= size(allLocations)

similar to k-closest-points-to-origin

My answer
vector<vector<int>> solution(vector<vector<int>> allLocations, int numRestaurants) {
	sort(allLocations.begin(), allLocations.end(), [&](vector<int> a, vector<int> b) { return a[0] * a[0] + a[1] * a[1] < b[0] * b[0] + b[1] * b[1]; }
	
	vector<vector<int>> res(allLocations.begin(), allLocations.begin()+numRestaurants);
	
	return res;
}

I'm sure you can even stop the sort with top N positions but I don't remember the function.

edit : it's nth_element

--

Question two

https://leetcode.com/discuss/interview-question/373202/Amazon-or-OA-2019-or-Optimal-Utilization

I didn't do very well on this question, 2 tests case didn't pass. I know why but didn't manage to fix it, with less stress I found what I should have write so its frustrating

Comments (2)