• + 2 comments

    Input is somehow ambiguous, for example

    3

    2 3

    -1 -1

    -1 -1

    2

    1

    1

    How can you assume that the root is 1 and another child is 2? And why are you swapping 1 twice? And what's the meaning of the -1 -1, -1 -1. Makes no sense to me.