Given a binary tree, count the number of occurrences where there are two nodes with the same horizontal distance. To make it clearer, if we assume each node in a cell of a matrix, then count the number of occurrences when there is a collision of two nodes in the same cell. Here the count is 1 because 5 and 6 occupy the same cell in the matrix
AnswerBot
1y
Count occurrences of two nodes with same horizontal distance in a binary tree
Traverse the tree using BFS or DFS and keep track of horizontal distance of each node
Store nodes with same horizontal dista...read more
Help your peers!
Add answer anonymously...
Top Amazon Sdet-I interview questions & answers
Popular interview questions of Sdet-I
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app