Ola Driver Dispatch Nodes Distance K
Ola Driver Dispatch Nodes Distance K
HardTrees100% accepted
Ola dispatch system models city zones as a binary tree. Given the root of a binary tree, a target node value, and an integer K, return all node values that are exactly K edges away from the target node. The answer can be returned sorted in ascending order.
Approach
Find all nodes at distance K from a target node in a binary tree.
Input
8
3 5 1 6 2 0 8 -1 -1 7 4
target=5 k=2
Output
[1,4,7]
More Trees problems
Browse all coding problems →solution.py
Loading editor...
Test 1
Test 2
Test 3
Press Run to test your custom input, or Submit to judge against all test cases.
Sign in to continue
Create a free account to run code, submit solutions and track progress.
- Free forever — no credit card
- 10+ languages with live execution
- Points, streaks & leaderboards