I also first thought of same solution given in the editorial but it will occupy more space as we are maintaining a vector or array at every node to store the indices and it can occupy a lot of space.
Please Check my code: Simple Solution
I also first thought of same solution given in the editorial but it will occupy more space as we are maintaining a vector or array at every node to store the indices and it can occupy a lot of space.
Please Check my code: Simple Solution
but this also trades off in time, the editorial solution will do it in lesser time, plus in worst case, space will also almost be same