Round 2: Coderpad
Questions:
-
Simple HashMap based: Parse apache log file to get most frequent logs
Leetcode Discussion -
Union find algorithm: Find root with max nodes in disjoint graphs specifically trees.
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 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 child to parent.Input:
{{1 -> 2}, {3 -> 4}}
Output:
2
Candidate's Approach
I initialized an array with -1 and while traversing the input, I populated the array for the index of the child with the parent. I kept checking if the parent of this child was already found, then just put that.
Interviewer's Feedback
No feedback provided.