Max Consecutive Ones III
Updated
Problem statement
Given a binary array nums and an integer k, you may change at most k zeroes into ones.
Return the maximum number of consecutive ones obtainable after those changes.
Function
longestOnes(nums: int[], k: int) → intExamples
Example 1
nums = [1,1,1,0,0,0,1,1,1,1,0]k = 2return = 6Changing the two zeroes between the first and last groups gives a longest run of six ones.
Example 2
nums = [0,0,1,1,1,0,0]k = 0return = 3No changes are allowed, so the existing run of three ones is optimal.
Constraints
1 <= nums.length <= 10^5nums[i]is0or1.0 <= k <= nums.length
More InMobi Phone Screen questions
- House Robber IPHONE SCREEN · Seen Aug 2026
- Word Break IIPHONE SCREEN · Seen Aug 2026
- Bus Station Seat AllotmentPHONE SCREEN · Seen Mar 2026
- Find Missing and Duplicate IntegerPHONE SCREEN · Seen Mar 2026
- Frequency Equals Card ValuePHONE SCREEN · Seen Mar 2026
- Frog Position After T SecondsPHONE SCREEN · Seen Mar 2026
- IPOPHONE SCREEN · Seen Mar 2026
- Evaluate DivisionPHONE SCREEN · Seen Dec 2025
- Compare Version NumbersPHONE SCREEN · Seen Feb 2022
- Count Array DerangementsPHONE SCREEN · Seen Feb 2022
Similar questions at other companies
- Sliding Window Attention over a KV CacheNVIDIA · PHONE SCREENNVIDIA interview questions
- 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
- Compact Conversations by Unique ListingsSierra · PHONE SCREENSierra interview questions
- Integer Compression OffsetHeadlands Technologies · PHONE SCREENHeadlands Technologies interview questions
- Shortest Window by Distinct-Value SumOracle · PHONE SCREENOracle interview questions
- Find Word-Multiset WindowsAmazon · PHONE SCREEN
- Max Consecutive Ones IIIEPAM · PHONE SCREENEPAM interview questions
- Max Consecutive Ones IIINykaa · PHONE SCREENNykaa interview questions