O21
Max Consecutive Ones III
Problem Statement & Objective
Given a binary array nums and an integer k, return the maximum number of consecutive 1's in the array if you can flip at most k 0's to 1's.
Function Signature (Python)
longest_ones_after_flips(nums: list[int], k: int) -> intInput & Output Contract
Output Rule:Maximum length of contiguous 1s with at most k flips.
System Constraints
1 <= nums.length <= 10^5
nums[i] is either 0 or 1
0 <= k <= nums.lengthExample Execution Walkthrough
nums = [1,1,1,0,0,0,1,1,1,1,0], k = 2
result: 6Example Test Scenarios (3)
Example 1
Input:
[[1,1,1,0,0,0,1,1,1,1,0],2]Expected Output:
6Example 2
Input:
[[0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1],3]Expected Output:
10Example 3: Tek Çevirme
Input:
[[0,0,0],1]Expected Output:
1