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
|
2450 Discussions
|
Please Login in order to post a comment
I am having timeout problems. any suggestions?
int swapCount = 0, n = arr.Length; for (int i = 0; i < n - 1; i++) { if (arr[i] != i + 1) { for (int j = i + 1; j < n ; j++) { if (arr[j] == i + 1) { swapCount++; arr[j] = arr[i]; break; } }
} } return swapCount;
python 3
using the data values range in problem definition:
Java - actually ignore the swap and update large element