What you see from the left
Reported in interviews at (where)
Stand to the left of a binary tree and look at it level by level, from the root down. On each level you see only the node furthest to the left.
Return the values you see, from the top level to the bottom one. An empty tree shows nothing.
- Input
root = [4,2,7,null,5,6]- Output
[4,2,5]
Level 1 shows 4, level 2 shows 2, and on level 3 the leftmost node is 5.
- Input
root = [1,null,3,null,8]- Output
[1,3,8]
Every node is a right child, but each is still the leftmost on its level.
Limits
0 <= number of nodes <= 10000-100 <= Node.val <= 100
Hints
Hint 1
Go level by level with a queue; the first node of each level is the one you see.
Where this was reported
Our own problem on the task these candidates describe; the wording, examples and tests are InternDoor’s.
Run your code to check it on the examples. Submit runs every hidden test.
