Goldman Sachs | Telephonic Round 2

Q1. Given a string "atdoer" and a dictionary {"to", "toe", "top"}, what is the maximum length word that can be formed using the letters in the string ,and that word must be present in dictionary as well.
For eg, in this case, answer will be "toe"

Q2. Given a forest of trees, write a function that will return the id of root of the tree having maximum number of nodes in it. If 2 trees have same number of nodes, then return the tree with smaller id. In any tree, each child will have single parent, but a parent can have multiple children. Input is given as a hashmap/dictionary, in which key is child id and value is parent-id.
For eg, INPUT: [[2,3], [5,7], [3,4], [6, 8], [1,4]]
OUTPUT: 4
Explanation: We have these trees: 2-> 3 -> 4 ; 5 ->7; 6 -> 8
1 ->4
Tree with '4' as root has maximum number of nodes i.e 4 nodes.

Comments (10)