GoLang Solution For LeetCode Problem: Minimum Number of K Consecutive Bit Flips
Solving Minimum Number of K Consecutive Bit Flips in go. Please try yourself first to solve the problem and submit your implementation to LeetCode before looking into solution.
Problem Description
Example 1:
Input: A = [0,1,0], K = 1
Output: 2
Explanation: Flip A[0], then flip A[2].
Example 2:
Input: A = [1,1,0], K = 2
Output: -1
Explanation: No matter how we flip subarrays of size 2, we can't make the array become [1,1,1].
Example 3:
Input: A = [0,0,0,1,0,1,1,0], K = 3
Output: 3
Explanation:
Flip A[0],A[1],A[2]: A becomes [1,1,1,1,0,1,1,0]
Flip A[4],A[5],A[6]: A becomes [1,1,1,1,1,0,0,0]
Flip A[5],A[6],A[7]: A becomes [1,1,1,1,1,1,1,1]
Note:
1 <= K <= A.length
1 <= A.length <= 30000
1 <= K <= A.length
A = [0 0 0 1 0 1 1 0] K = 3 A = [2 0 0 1 0 1 1 0] i = 0 flippedTime = 1 A = [2 0 0 1 0 1 1 0] i = 1 flippedTime = 1 A = [2 0 0 1 0 1 1 0] i = 2 flippedTime = 1 A = [2 0 0 1 0 1 1 0] i = 3 flippedTime = 0 A = [2 0 0 1 2 1 1 0] i = 4 flippedTime = 1 A = [2 0 0 1 2 2 1 0] i = 5 flippedTime = 2 A = [2 0 0 1 2 2 1 0] i = 6 flippedTime = 2 A = [2 0 0 1 2 2 1 0] i = 7 flippedTime = 1
See the full details of the problem Minimum Number of K Consecutive Bit Flips at LeetCode
Originally posted at: @github.com/halfrost/LeetCode-Go
Comments
Leave a comment
You are not LoggedIn but you can comment as an anonymous user which requires manual approval. For better experience please Login.