Tap here to switch tabs
Problem
Submissions

Problem: Minimum Adjacent Swaps for K Consecutive Ones

med
30 min
Try to solve the Minimum Adjacent Swaps for K Consecutive Ones problem.

Statement

You are given an integer array nums containing only 00’s and 11’s, and an integer k.

In a single move, you can swap two adjacent elements in nums.

Return the minimum number of moves required to group any k occurrences of 11 into a contiguous subarray.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • nums[i] is equal to 00 or 11.

  • 1≤1 \leq k ≤\leq sum(nums)

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Adjacent Swaps for K Consecutive Ones

med
30 min
Try to solve the Minimum Adjacent Swaps for K Consecutive Ones problem.

Statement

You are given an integer array nums containing only 00’s and 11’s, and an integer k.

In a single move, you can swap two adjacent elements in nums.

Return the minimum number of moves required to group any k occurrences of 11 into a contiguous subarray.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • nums[i] is equal to 00 or 11.

  • 1≤1 \leq k ≤\leq sum(nums)