Dsa
Sliding Window
Medium
Find Maximum Consecutive Ones
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:
- A single line containing binary integers (0 or 1) separated by spaces, followed by an integer k (0 <= k <= |nums|).
Output:
- Print the length of the longest subarray of consecutive 1's that can be achieved by flipping at most k 0's.
Example:
Input:
1 0 1 0 1 1 0 1 1 1 0 1 2
Output:
8
Key concepts
sliding_windowarraycounting
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now