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?
Used the same approach in the contest… Got a TLE! The NOP idea did not strike! Nice one
okay, I think I get it. Thanks
My O(N^2) algo failed!! Someone is lying!
You can try submit my code and check
even I used the same concept but got WA, missed some case somewhere I think. Onto it now. Nice exp btw