#K74482. Left View of Binary Tree
Left View of Binary Tree
Left View of Binary Tree
Given a binary tree, your task is to compute its left view. The left view of a binary tree is the set of nodes visible when the tree is viewed from the left side.
You are provided with the level order traversal of the tree as a single line from standard input (stdin). Each token represents a node's value or the string null
if the node is missing. Your program should reconstruct the binary tree from this input, compute its left view, and then print the resulting node values (separated by a space) to standard output (stdout).
Recall that the left view includes the first node encountered at each level when traversing the tree from left to right. The recursive relation can be expressed as: \(\text{if } level > maxLevel:\; result.push(node)\).
inputFormat
A single line containing the level order traversal of the binary tree. Each token is separated by a space and is either an integer or the word null
(which represents a missing node).
outputFormat
A single line containing the left view of the tree. The node values are printed in order and separated by a space.
## sample1 2 3 null null 4 5
1 2 4