Goldman Sachs | Coderpad | Software Engineer Associate
Anonymous User
1052

There were 2 DSA problems, 1 easy and 1 medium.

Problem 1: Was the same as Josephus Problem, just differenty phrased.

Problem 2: Find the root with max nodes in disjoint graphs(trees).
A forest is represented with a hashmap. This hashmap has this relationship
key -> value :: child -> parent
We need to find out the largest tree's root node. In-case of a tie, return the smaller root value.

Eg:
Input:
{{1 -> 2}, {3 -> 4}}
Output:
2

My Soln: used DisjointSet

Was able to solve the 1st problem completely, but failed 2 test cases for the 2nd :(
Final decision: I was asked to take another coderpad round!

Comments (3)