Please find the problem

My code is passing all the custom test cases but fails the code checker

hello @Garvit012
ur logic is correct.
you r getting wa because your preorder output is not matching with required output. (because ur construted tree is bit different.)

changed ur buildtree function a bit .
check ur updated code.

Yes i have tried this build function in previous questions…wanted to challenge myself with some constraints…can please point out the mistake in my approach

let say n->6
u will choose n/2-> 3 as the mid node.
but the function that i shared will choose (0+5)/2 -> 2 as the mid node.
clearly both approaches are selecting different node as mid node .
that is why the tree constructed from both approaches are differnt.

ohhh means if i change to mid=n/2 to n-1/2 it should work?

its working…thanks a lot aman bhaiya you always save me and resolve my doubts to the best

:+1:. . … …