how to take input ? I’m not getting any intuition
and also the process to check identical structure
Structurally identical binary tree
Hey,you can maintain a queue,for every true input take data and make queue parent left child/right child equal to that value and push new node with current data to the queue.
As far as solving ,for every node see if other tree have a node as well at that point , if not return false, else return true.
You can implement it using recursion
how to implement this ?
implemented as you said, works correct for sample test case but getting TLE 3 test cases
added one more condition, now getting run error in 2 test cases
Hey, i have made some changes to your code.Now, try to run it.
your code is giving compilation errors
i have edited little bit
still getting run error in 2 test cases
Hey, sorry for late reply.I don’t check mail that frequently.
I have made some changes to your code and now it is getting accepted .
Your isidentical function was wrong as well as your use of deque was wrong.You were inserting and poping from one end only which was wrong, it will work as a stack then while we want queue functionality.
yes, it is accepted
your build function is building the tree in level order manner, but in question input is given in preorder manner
10 true 20 true 40 false false true 50 false false true 30 true 60 false false true 73 false false
bfs on this input according to your build function gives output as
10
20 40
50
30
60
73
instead it shoud be as
10
20 30
40 50 60 73
Hey, thanks for pointing it out.
I will make a solution using pre-order input and will see if it is getting accepted or not.
I will let you know the solution if it gets accepted.
see my previous build function was correct, only problem was there in isIdentical function, it is accepted now