There were total 4 questions (1 main question and 3 follow ups on the same). It was conduted on hackerrank pair programming portal. Time provided was 1 hour. The interviewer just gave me the questions and asked me to explain the solution and then code it.


These were the follow ups:





I was able to code the solution for the problem using union and find approx. Passes 5/5 test cases. He was expecting something O(1) for the follow ups which I couldn't answer in the given time. I came up with O(n) approach for the follow up question.
Verdict: Got an instant mail with rejection in 1 min.