Round 2
Questions: Given a binary tree, you need to find a pair of two nodes such that their sum of values is equal to target. Constraints:
- Distance between two nodes should be equal to d
- Both nodes should not be at the same level
Return true if found any such pair of nodes. Note: Tree can contain duplicate values.
Possible node pairs which are at distance 3 are: (3,8), (0,8), (7,4), (1,5), (2,4) etc. By distance, I mean the number of edges in the shortest path connecting two nodes.
Candidate's Approach
I didn't come up with an optimal solution, rather with O(n^2) time complexity.
Interviewer's Feedback
No feedback provided.