Unable to Understand

CAn u please help me how to apprach with this question

The problem can also be solved using simple recursive traversal. We can keep track of level of a node by passing a parameter to all recursive calls. The idea is to keep track of maximum level also. Whenever we see a node whose level is more than maximum level so far, we print the node because this is the first node in its level (Note that we traverse the left subtree before right subtree)

iterative approach can be

  • Do a level order traversal.
  • Push NULL into the queue to mark the end of each level.
  • Print the data of root of data and start with level order traversal.
  • As you encounter a NULL, print the next element.
  • Otherwise skip all the other elements

Thank you for the support.Got it

1 Like