The testcases are weak. If i perform preorder traversal for both, it gives the correct ans, though that shoudl not be the case. Eg: 7 1 2 -1 3 -1 -1 and 7 1 -1 2 -1 -1 3 will have same preorder but they are different trees.
2 different trees can give same preorder traversal, which is why you need to do either inorder or postorder to differentiate.
are you first doing preorder traversal of both the trees and then comparing the sequence?
there is no need for that we can do this even in a preorder state checking at each point if one node has become null and other has not then they are not equal and if the current node’s data is not equal to other node’s then it is not equal.
return & of left and right recursive calls