Max Consecutive Ones III
Updated
Problem statement
Given a binary array nums and an integer k, return the maximum number of consecutive ones obtainable by flipping at most k zeros to ones.
Function
longestOnes(nums: int[], k: int) → intExamples
Example 1
nums = [1,1,1,0,0,0,1,1,1,1,0]k = 2return = 6Flipping two zeros creates a six-element run.
Example 2
nums = [0,0,1,1,1,0,0]k = 0return = 3Without flips, the central run has length three.
Example 3
nums = [0,0,0]k = 3return = 3All three zeros can be flipped.
Constraints
0 ≤ nums.length ≤ 100000.- Every value in
numsis0or1. 0 ≤ k ≤ nums.length.
Source note: Author-written prompt excerpt retained for source fidelity.
More Nykaa interview questions
- Employees Who Earn More Than Their ManagersPHONE SCREEN · Seen Nov 2026
- Longest Substring Without Repeating CharactersPHONE SCREEN · Seen Nov 2026
- Remove Duplicates from Sorted ArrayPHONE SCREEN · Seen Nov 2026
- Course SchedulePHONE SCREEN · Seen Sep 2026
- Reverse a String Keeping Dashes in PlaceONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Subarray Product Less Than KApple · PHONE SCREENApple interview questions
- Subarray Product Less Than KAngel One · PHONE SCREEN
- Subarray Product Less Than KThe D.E. Shaw Group · PHONE SCREENThe D.E. Shaw Group interview questions
- Max Consecutive Ones IIIAmazon · PHONE SCREEN
- Compact Conversation History by Token BudgetSierra · PHONE SCREENSierra interview questions
- Count Subarrays With Product Equal to KSalesforce · OASalesforce interview questions
- Shortest Window with Required CountsOracle · ONSITE INTERVIEWOracle interview questions
- Count Belt Sections With K Fruit Pairs (Forward Deployed Engineer)Boston Consulting Group · OABoston Consulting Group interview questions
- Longest Binary Window with at Most K OnesLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- Count Hotspot Playback WindowsGoogle · ONSITE INTERVIEWGoogle interview questions