Amazon | OA (SDE -1) | Implement an algorithm to find plan for the closest X destinations

My assessment was completed recently. I am sharing the questions asked. Please feel free to suggest the approach.
One thing more, not only you have to solve coding problems, but also, you need to explain the approach and time complexity on a seperate notepad.

PLEASE UPVOTE IF YOU FIND IT USEFUL.

Here we go with the question:
Question : 1
Given a list of N possible delivery destinations, implement an algorithm to create the delivery plan for the closest X destinations.

Input
The input to the function/method consisits of two arguments:
allLocations, a list where each element consists of a pair of integers representing the x and y coordinates of the delivery locations;
numDeliveries, an integer representing the number of deliveries that will be delivered in the plan(X).

Output
Return a list of elements where each element of the list represents the X closest x and y integer coordinates of the delivery destinations, where X represents the numDeliveries input. If there is one tie, use the location with the closest X coordinate. If no location is possible, return a list with an empty location - not just an empty list.

Constraints
numDeliveries<=size(allLocations)

Note
The plan starts with the truck's location [0.0]. The distance of the truck from a delivery destination (x,y) is the square root of x^2 + y^2. If there are multiple ties, then return the locations starting with the closest X-coordinate as long as you satisfy returning exactly X delivery locations. The returned output can be in any order.

Example
Input

allLocations = [ [1,2], [3,4], [1,-1]]
numDeliveries = 2

Output
[ [1,-1], [1,2]]

Explaination
The distance of the truck from loaction [1,2] is square root(5) = 2.236.
The distance of the truck from loaction [3,4] is square root(25) = 5.
The distance of the truck from loaction [1,-1] is square root(2) = 1.414.

numDeliveries is 2, hence the output is [1,-1] and [1,2].

Question 2: https://leetcode.com/discuss/interview-question/1777426/Amazon-Online-Assessment-(follow-up)

Comments (11)