Amazon SDE 1 Round 2
Difficulty: MEDIUMCategory: InterviewExperienceFrequency: 1Asked On 2025-02-25Added By Anonymous
Source: Link
Company: Amazon
Role: SDE I
Interview Stage: Onsite
Location: unknown
Year: unknown
Original Post Content:
30 min LP questions and one coding problem
problem statement:
Given a binary tree, you need to find a pair of two nodes such that their sum of values is equal to target.
Constraints:
1: distance between two nodes should be equal to d
2: both nodes should not be at same level
return true if found any such pair of nodes
Note: tree can contain duplicate values
I didn't come up with optimal solution rather with O(n^2) TC
possible node pairs which are at distance 3 are: (3,8), (0,8), (7,4), (1,5) , (2,4) etc.
By distance i means number of edges in shortest path connecting two nodes.
You can share our approach