i pretty much had the same solution, 1. create tree 2. swap 3. perform inorder traversal i didnt know that python recursion limit needed to be changed, i was pulling my hair out because the 2 of 12 test cases kept failing
we must swap every level that is a multiple of k. ex: if k = 2, we must swap levels 2, 4, 6 etc. so by using level%k==0 we are swapping every level that is a multiple of k
Hi OP, I seen quite a bit of approaches where people would just all together change the intention of this format of input, by just making it into a familiar structure of actual tree data structure. But, since the underlying knowledge point is about abstract inorder tree traversal. Would it be feasible to do it using the mathematical form of tree traversal? (meaning not physically change the input structure, and just jump from one index to the next via the 2^k difference from each depth of tree.) Would you have an approach like that?
@@HackersRealm if you get it working, please let me know! I only got it working for the test case 0 as it's restrained somehow by my swap iterations so I never get to traverse the entire tree.
@@ajitagupta746 level is initailly set to 1 because the root node is located at level 1 and every time we have to start from root node. But I don't get why do we need the modulo?
Like if we want to swap nodes at level 10, then according to the algorithm why would we swap nodes at level 2, since we encounter level 2 while traversing?
This is far better explanation than any other on UA-cam of this question.
Glad you liked it!!!!
Whoever wrote this problem description needs to be fired immediately
i pretty much had the same solution,
1. create tree
2. swap
3. perform inorder traversal
i didnt know that python recursion limit needed to be changed, i was pulling my hair out because the 2 of 12 test cases kept failing
yeah it happens
Aswin you are the goat! I have been watching a ton of your videos recently and you give great explanations. Thank you!
Thanks for your kind words!!! I will try my best to post more videos!!!
Great explanation...you made it simple...
Glad it was helpful!!!
Hi Aswin! Thank you for all these hackerrank videos!
Could you please explain why level % k == 0 instead of level == k.
thanks!! There will be multiple levels in the tree that's why we didn't use equals as it only changes one level
we must swap every level that is a multiple of k. ex: if k = 2, we must swap levels 2, 4, 6 etc. so by using level%k==0 we are swapping every level that is a multiple of k
Thnak youu
😇😇
Hi OP, I seen quite a bit of approaches where people would just all together change the intention of this format of input, by just making it into a familiar structure of actual tree data structure. But, since the underlying knowledge point is about abstract inorder tree traversal. Would it be feasible to do it using the mathematical form of tree traversal? (meaning not physically change the input structure, and just jump from one index to the next via the 2^k difference from each depth of tree.) Would you have an approach like that?
It would be possible, need to think about that and try it for some base cases
@@HackersRealm if you get it working, please let me know! I only got it working for the test case 0 as it's restrained somehow by my swap iterations so I never get to traverse the entire tree.
This problem is very difficult how can solve that so easily bro please tell me
When you solve problems, you can use some of the logic for new problems, that's how i did it!!!
it is very difficult to crack this with logic how u build that please tell the wa.i have to see solution to almost every problem ..it is very sad..
Each person think in different way. I guess by exploring these techniques you will get your own way of logic
all test cases are still not clear
Which one is not clear?
I don't understand why we do level%k? And why is level set to 1 for all queries? 1%k is weird.
When we reach that level, we swap the nodes, or else we move to the next level, that's the logic
@@HackersRealm all children of k are stored at k*number, that's why we do modulo, Right?
@@ajitagupta746 level is initailly set to 1 because the root node is located at level 1 and every time we have to start from root node. But I don't get why do we need the modulo?
Like if we want to swap nodes at level 10, then according to the algorithm why would we swap nodes at level 2, since we encounter level 2 while traversing?