Facebook | Phone | Two sum in Binary Tree
Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2020-05-19Added By Anonymous
Source: Link
Company: Meta
Role: unknown
Interview Stage: Phone Screen
Location: unknown
Year: unknown
Original Post Content:
Given a binary tree and an integer K, return two nodes which are at different levels and their sum is equal to K.
Constraints:
1. Tree can have duplicate values.
2. In case more than one pair is available in the tree, then return any of the pair.
I gave a solution based on DLL and HashMap, but it is not very optimised. This led to rejection :(
Please let me know your thoughts on this.