You are viewing a single comment's thread. Return to all comments →
Whats wrong, it seems they have added that testcase-14 not far ago. Anyway for that test case we need to tweak the solution and it pass it:
static int minimumSwaps(int[] arr) { int arrLen = arr.length; int count = 0; int [] sarr = arr.clone(); Arrays.sort(sarr); for (int i = 0; i < arrLen; i++) { if (arr[i] != sarr[i]) { count++; for (int j = i + 1; j < arrLen; j++) { if (arr[j] == sarr[i] ) { int tmp = arr[j]; arr[j] = arr[i]; arr[i] = tmp; break; } } } } return count; }
Seems like cookies are disabled on this browser, please enable them to open this website
Minimum Swaps 2
You are viewing a single comment's thread. Return to all comments →
Whats wrong, it seems they have added that testcase-14 not far ago. Anyway for that test case we need to tweak the solution and it pass it: