[Approach - 1] Using Depth-first search (DFS) - O(n) Time and O(n) Space
The idea is to use DFS and Keep track of current level. For every level of the binary tree, the first node we see from the left side is part of the left view.
Output
1 2 4 5
[Approach - 2] Using Level Order Traversal (BFS) - O(n) Time and O(n) Space
The left view contains all nodes that are the first nodes in their levels. A simple solution is to do level order traversal and print the first nodein every level.