#K82177. Left View of Binary Tree

    ID: 35918 Type: Default 1000ms 256MiB

Left View of Binary Tree

Left View of Binary Tree

You are given a binary tree represented in level‑order format. In this format, the tree nodes are given as space‑separated values, and a value of N represents a null node. The left view of a binary tree is defined as the set of nodes visible when the tree is viewed from the left side; that is, the first node encountered at each level.

For example, consider the tree represented by the input:

1 2 3 4 5 6 7 N N N 8

The tree corresponds to:

              1
            /   \
           2     3
          / \   / \
         4   5 6   7
              \
               8

The left view of this tree is: 1 2 4 8.

Your task is to compute the left view of the given binary tree and output the result as a sequence of space‑separated integers.

inputFormat

A single line containing the level‑order traversal of a binary tree, with each value separated by a space. Use 'N' to denote a null node. For example:

1 2 3 4 5 6 7 N N N 8

outputFormat

A single line containing the left view of the binary tree as space‑separated integers. For example:

1 2 4 8
## sample
1 2 3 4 5 6 7 N N N 8
1 2 4 8