We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
- Minimum Swaps 2
- Discussions
Minimum Swaps 2
Minimum Swaps 2
Sort by
recency
|
2447 Discussions
|
Please Login in order to post a comment
Java - actually ignore the swap and update large element
The constraints indicate that the problem is simpler than initially perceived. Given that each integer 'x' must be less than or equal to the array's size, and 'x' is at least 1, the elements in the array will range from 1 to the size of the array. Initially, I considered the possibility of arrays like {10, 1000, 47, 7, 35, 2}, which would require a more intricate algorithm to determine the correct position of each integer within the array, as it would be relative to the other values in the array. However, as per the problem's constraints, the position of an integer 'x' in the array must be 'x-1'.
Java solution:
javascript
I knew this required counting the no. of swaps done in a known sorting algorithm...
This is selection sort.