Interviewer started with two behavioural questions. Later said based on speed I'll do one or two problems. I was able to do only one.
Question : Given pairs like [(5,1)(4,5)(9,4)(11,9)(9,4)]
Return [(11,9)(9,4)(4,5)(5,1)] - The start point has to be same as the end point of the previous.
Need to return exception in case of empty or duplicate inputs.
Solution:
Found the starting point, on searching for a pair who has a start pt that is not an end point of any other pair - Used Set to achieve this.
Stored pairs as Key value pairs in Map.
Added pairs when a match is found till the Map is empty.
Space & Time O(n)
Passed all test cases. But not sure if I will get a call, as I solved only one question.