rachitiitr's blog

By rachitiitr, history, 7 years ago, In English
  • Vote: I like it
  • +8
  • Vote: I do not like it

»
7 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Here is another problem which can be solved using a similar merge technique. My solution.

»
7 years ago, # |
  Vote: I like it +8 Vote: I do not like it

Btw, your implementation for the original problem is not completely correct. While you need to travel the whole map of each node your solution become O(n^2logn)