Today I had my coderpad round with GS. We dived straight into the code. This was the First question: https://leetcode.com/discuss/interview-question/1837422/Goldman-Sachs-or-Coderpad-or-First-non-repeating-character
Second question:
https://leetcode.com/discuss/interview-question/1837465/Goldman-Sachs-or-Coderpad-or-Find-the-maximum-gold-that-can-be-collected
I had solved two questions within 30 minutes so the interviewer asked me this third question:
A forest is represented with a hashmap. This hashmap has this key -> value relationship: child -> parent.
Every node has a unique integer element. I needed to find out the largest tree's root node. If there is a tie, return the smallest root.
The tree with the highest number of nodes, is the largest one. The edges are directed from parent to child.
Input:
{{1 -> 2}, {3 -> 4}}
Output:
2
I first found out the roots present in the forest. Then created an adjacency list and applied BFS to count the nodes. Maintained the maximum count and root with the largest tree in two variables.
Hope it helps.
Edit: Link for the next rounds - https://leetcode.com/discuss/interview-experience/1939593/goldman-sachs-analyst-bengaluru-selected/1406618