Practice Minimum Number of K Consecutive Bit Flips
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Minimum Number of K Consecutive Bit Flips
Problem Statement
You are given a binary array nums and an integer k. A k-bit flip is choosing a subarray of length k from nums and simultaneously changing every 0 in the subarray to 1, and every 1 in the subarray to 0. Return the minimum number of k-bit flips required so that there is no 0 in the array. If it is not possible, return -1. A subarray is a contiguous part of an array.
Source: Minimum Number of K Consecutive Bit Flips on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
nums = [0,1,0], k = 1
2
# Example 2
nums = [1,1,0], k = 2
-1
# Example 3
nums = [0,0,0,1,0,1,1,0], k = 3
3
Constraints
Related LeetCode Problems
Practice more problems similar to Minimum Number of K Consecutive Bit Flips.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.