educative.io

What should we do if a level has only one node and it should be in the left/right view based on left/right child of its parent node?

In this problem, for example, the root is only included in the left view; similarly, if a level has only one node we should include it in the left view.

How about we include it in left view if the node is the left child of its parent node and we include it in right view if the node is the right child of its parent node?

Any ideas?

This will be a good variation of the original problem. Did you try writing its algorithm?

The leftview rightview solution will not work. On one particular level it could be that one node is on the rightside of the previous level and there is only one node on that level but you included on the leftview instead of the rightview.