Guess Your Way Out

anybody explain me last test case output 10 i am getting 11.

sample input

5
3 8
2 3
1 2
2 4
3 6

sample output

14
5
2
6
10

another things i am not getting
following statement of problem

"
If the destination node is already visited, Amr skips current command, otherwise he moves to the destination node;
If Amr skipped two consecutive commands, he goes back to the parent of the current node before executing next command;
If he reached a leaf node that is not the exit, he returns to the parent of the current node;
"

Hi

ans is 10
coloured is destination. and numbers of node are their order

If the destination node is already visited, Amr skips current command, otherwise he moves to the destination node >>> this means if the node he has to visit with the command is already visited then he doesn’t go to the node.

If Amr skipped two consecutive commands, he goes back to the parent of the current node before executing next command >> means the left and right child of the node are visited(this means complete tree under this node is visited ) then he comes back to the parent.

If he reached a leaf node that is not the exit, he returns to the parent of the current node >> this is self explanatory :stuck_out_tongue:

i am getting it. but how you skip left of node 10 or how to figure out that this node is already visited ?
below is code i had implement.

it give me wrong answer.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.