1703. Minimum Adjacent Swaps for K Consecutive Ones
https://leetcode.com/problems/minimum-adjacent-swaps-for-k-consecutive-ones
Description
You are given an integer array, nums
, and an integer k
. nums
comprises of only 0
's and 1
's. In one move, you can choose two adjacent indices and swap their values.
Return the minimum number of moves required so that nums
has k
consecutive 1
's.
Example 1:
Example 2:
Example 3:
Constraints:
1 <= nums.length <= 105
nums[i]
is0
or1
.1 <= k <= sum(nums)
ac
Last updated