You are viewing a single comment's thread. Return to all comments →
In python had to change recursion limit to work on the last two test inputs
I used a loop with a deque as a stack instead to get around that problem
I used a loop with a deque as a queue too but it didn't get around that problem with that solution
You can use even the list() and it works. See the "Iterative InOrder traversal" example:
here on wiki
Thanks for the tip
Amazing! This is exactly what I hoped to find in the comments. Thanks!
what prerequisite i need to solve this question
solve level order traversal first. the logic here is similar.
i'm confused, we have to swap nodes(means that whole node containing its child nodes are also moved form left to right or right to left) or we have to swap nodes data.
We have to swap nodes not their data.
I did the same thing but am getting time out in test cases 6,7,10 and 11. Can any one suggest some thing?
same here bro, i first created a tree then inserted nodes acoordingly on the basis of input then swapped but it is giving timeout in test case 6,7,10,11.
please provide me an update as soon as u get it,and ill do the same
Thank you so much! Would never have figured that out.
Awesome, I finally got every test past! Thanks.
I never knew there was recursion limit, thanks!!
Ha! Good trick.
It was fun to work out the in-order traversal using a list-based stack though :)
By the way, a recursion limit of 1200 is sufficient.
(1024 is too small for sure.)
Thanks a lot!!
You saved my life bro. I just started coding in python so didn't know that such a thing exists. I was getting this error for past half an hour!Thanks
THANK YOU! I've been trying to memoize the shit out of this problem after passing all of the other test inputs, can't believe all I had to do this whole time was set the recursion limit
Thanks! Saved me a lot of time for needless debugging. Code was (in principle) ok.