I dont know if you have figured it out or not. But just in case you haven't: When we swap 2 elements, the i increases to the next element (i + 1) and in some cases the ith element is still not in the right position and if we move ahead, it will remain in the wrong position, so we keep coming back to that ith element repeatedly until the element is in its right position and once it is, we move ahead without any issues.
pls make a video on minimum swap to sort in case of duplicate element in string
Horrible Audio
What's the time and space complexity of this code
what is i - - is for?
I dont know if you have figured it out or not. But just in case you haven't:
When we swap 2 elements, the i increases to the next element (i + 1) and in some cases the ith element is still not in the right position and if we move ahead, it will remain in the wrong position, so we keep coming back to that ith element repeatedly until the element is in its right position and once it is, we move ahead without any issues.
U can use while loop instead of that i--
@@yash_______105 yes using while is much clear in that case and it works.
@@abhigyanraha5620 correct, in case the example vector is so complex. In this video, sir has taken a simple one.