This was the second question int the assesment.
platform- Hackerrank
position -SDE 1 India
2 YOE
Question: given a list of forward routes and reverse routes and the maxTravelAllowed: return the most optimal pairs
ex1: maxTravelDist = 10000
forwardRouteList[] = [1,3000],[2,5000],[3,7000],[4,10000]
returnRouteList[] = [1,2000],[2,3000],[3,4000],[4,5000]
Op: [[2,4],[3,2]]
ex2:
maxTravelDist = 10000
forwardRouteList[] = [1,3000],[2,5000],[3,7000]
returnRouteList[] = [1,4000],[2,6000],[3,1000]
Op: [[2,1],[3,2]]
Here no pair has sum equal to 10000 but 2 pairs have 9000, so this will be the answer in this case.
Approach: firstly did it in O(N^2) but it was giving TLE for half TCs.
Then used 2 maps, first stored maxTravelDist - forwardRouteList[i][1] and second stored dist as key and index as values. Then iterate over fwdMap and find if same value is present in reverseMap.
Couldn't pass all the TCs. 10/17 were passed.
First ques: https://leetcode.com/discuss/interview-question/1459905/Amazon-or-OA-or-K-Closest-Points-to-Origin
Pls pray that I get the call.
All the best! :)