okay, take a look at the tree in the pic above. if you remove node 7, what is the complexity of merging the tree? Put the node 7 as a child to node 5, now how much time will it take?
1 Like
Used the same approach in the contest… Got a TLE! The NOP idea did not strike! Nice one
3 Likes
okay, I think I get it. Thanks
My O(N^2) algo failed!! Someone is lying!
2 Likes
You can try submit my code and check
1 Like
even I used the same concept but got WA, missed some case somewhere I think. Onto it now. Nice exp btw