Given a generic tree, find the count of all special nodes. A node is a special node if there is a path from root to that node with all distinct elements. The input was not a pointer to a tree. He’d give me an adjacency list and an array of values where the value of ith node in the adjacency list is the ith element in the values array. He asked me not a create a tree out of the given information and rather do it with the adjacency list itself.
I suggested to do a depth first search keeping a set which contains all elements upto a given node. Once I reach a particular node, I check if it’s already in the set. If its already in the set, I ret...read more
We will do a recursive Depth First Search keeping a vector/list to check for the distinct element.
- We start the recursive DFS from the “root” node with an empty vector/list.
- Let’s say we are at some ...read more
We will do a recursive Depth First Search keeping a HashMap/Dictionary to check for the distinct element.
- We start the recursive DFS from the “root” node with an empty HashMa...read more
Top Amazon Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Amazon Software Developer
Reviews
Interviews
Salaries
Users/Month