Tree Left View using Level Order Traversal Recursive

I am doing level order traversal recursive, and trying to print just the first node of each level. Getting one test case wrong.
Here is the code.

@Kishan-Mishra-2464674013761441
Try this testcase :
Input :
1 2 3 -1 -1 -1 4 -1 5 -1 6 -1 -1

Expected Output :
1 2 4 5 6

Your Output :
1 2

Hint : Work on your ‘flag’ variable.

I know there is something wrong with flag variable, but i am not able to fix it. Help me out with that

@Kishan-Mishra-2464674013761441
Try passing flag as a reference variable and do not increment it in the recursive calls , only change it in the if statement where you are printing the data.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.