Max Consecutive Ones III
Finding Longest Subarrays (Standard Sliding Window) DSA practice problem on Onlearn.
Difficulty: medium.
Topics: Max Consecutive Ones III, Arrays, Sliding Window, Two Pointers, Optimization, Time Complexity, Space Complexity, Loops, Conditional Statements, array traversal, sliding window, optimization, two pointer technique, Data Structure Operations.
Max Consecutive Ones III 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. Input Specification: The input consists of two lines. The first line contains a list of integers nums, representing the binary array. The second line contains a single integer k, representing the maximum number of 0s that can be flipped. Output Specification: Return an integer representing the maximum number of consecutive 1's. Constraints: 1 <= nums.length <= 10^5 nums[i] is 0 or 1 0 <= k <= nums.length Sample Input: nums = [1,1,1,0,0,0,1,1,1,1,0], k = 2 Sample Output: 6 Explanation: Flip the two 0s at index 3 and 4 to 1s. The array becomes [1,1,1,1,1,0,1,1,1,1,0]. The longest subarray of 1s has length 6 (from index 3 to 8).