852. Left View of Binary Tree

EasyTreesBinary TreeBFSTraversal

Given the root of a binary tree, return its left view — the first node seen at each level when looking from the left side, ordered top to bottom. The tree is given as a level-order array with null for missing children.

Input: A level-order array of the tree.

Output: Array — the leftmost node value per level.

Examples

Example 1
Input: [1,2,3,4,5,null,6]
Output: [1,2,4]
Explanation: Leftmost node at each depth.
Example 2
Input: [1]
Output: [1]
Explanation: Single node.
Example 3
Input: []
Output: []
Explanation: Empty tree.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →