Skip to content

Commit

Permalink
Add some code
Browse files Browse the repository at this point in the history
  • Loading branch information
codeAbinash committed Aug 4, 2024
1 parent 47af7d3 commit 3b33e64
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import java.util.Arrays;

class Solution {
public int minSwaps(int[] nums) {
int k = Arrays.stream(nums).sum();
int n = nums.length;
int count = 0;
for (int i = 0; i < k; ++i)
count += nums[i];
int max = count;
for (int i = k; i < n + k; ++i) {
count += nums[i % n] - nums[(i - k + n) % n];
max = Math.max(max, count);
}
return k - max;
}
}

0 comments on commit 3b33e64

Please sign in to comment.