Code might be Wrong!?

Sir, in the video “Binary Tree- Preorder build and print” for test case 1 2 3 4 5 6 -1 -1 -1 -1 -1 -1 -1 the logic you mentioned is failing, if I print its inorder it is showing 6 5 4 3 2 1 instead it should print 4 2 5 1 6 3,Because I think it is always calling its left side first, so the tree is building in a left skew fashion.

Hello @Varun97,

Sir has explained the correct logic.
There is no mistake in the code.

The input you have specified is itself a left-skewed binary tree.
So, the inorder coming is also true i.e. 6 5 4 3 2 1

To obtain the inorder you have specified the tree should look:
____________1
______2 ___________3
_4 ________5 _6 __________
and the input should be:
1 2 4 -1 -1 5 -1 -1 3 6 -1 -1 -1

Code:

Hope, this would help.
Give a like if you are satisfied.