You are viewing a single comment's thread. Return to all comments →
Your solution may fail if input numbers are not in increment order. For example,
3
3 -1
2 -1
-1 -1
2
1
(while it works when in order:
1 )
One more example:
5
4 5
-1 3
The problem is because you use the input value as array index.
Seems like cookies are disabled on this browser, please enable them to open this website
Swap Nodes [Algo]
You are viewing a single comment's thread. Return to all comments →
Your solution may fail if input numbers are not in increment order. For example,
3
3 -1
2 -1
-1 -1
2
1
1
(while it works when in order:
3
2 -1
3 -1
-1 -1
2
1
1 )
One more example:
5
4 5
2 -1
-1 3
-1 -1
-1 -1
1
1
The problem is because you use the input value as array index.