what conditions i am missing. please point it out.
link to my code - https://ide.codingblocks.com/s/248908
Test case failure
the two nodes need not necessarily be continuous
what u are doing right now, it simply exchanging two consecutive values if they do not satisfy the condition for bst, but exchanging them will still not ensure a bst
suppose two random values from the right subtree and one from the left subtree are swapped, simpy exchanging the root with one of the exchanged values will not help
the code i have pasted gives the implementation of the right logic
u can use this function to refer to the correct logic
see i will give an example
3
1 4
2 5
let’s say i swap 1 and 5
according to ur logic it will 3 AND 5 as the answer
but even on switching 3 and 5 it is still not a bst