Max Consecutive Ones III (for E5 :)
Updated
Problem statement
This is Max Consecutive Ones III, LC 1004 :)
The other question was - Get Minimum Round Trip Cost (: for E4 && E5 :) --> Click me, I ma a link~
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.
Function
longestOnes(nums: int[], k: int) → int
Complete the function longestOnes in the editor.
longestOnes has the following parameters:
- 1.
int[] nums: a binary array - 2.
int k: the maximum number of 0's that can be flipped
Returns int: the maximum number of consecutive 1's
Examples
Example 1
nums = [1,1,1,0,0,0,1,1,1,1,0]k = 2return = 6[1,1,1,0,0,1,1,1,1,1,1] Bolded numbers were flipped from 0 to 1. The longest subarray is underlined.
Example 2
nums = [0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1]k = 3return = 10[0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1] Bolded numbers were flipped from 0 to 1. The longest subarray is underlined.
Constraints
1 <= nums.length <= 10^5nums[i]is either 0 or 1.0 <= k <= nums.length
More Meta Phone Screen questions
- Convert a Sorted Linked List to a Balanced BSTPHONE SCREEN · Seen Nov 2026
- Fuzzy Word Lookup With One Misspelled LetterPHONE SCREEN · Seen Nov 2026
- Multi-Head Attention Forward PassPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Run-Length Encoded Vector Dot ProductPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Mutual-Friend RecommendationsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Best Time to Buy and Sell StockPHONE SCREEN · Seen Nov 2026
- First Element Greater Than KPHONE SCREEN · Seen Nov 2026
- Count Events in Rolling Minute WindowsPHONE SCREEN · Seen Oct 2026
- Valid Word AbbreviationPHONE SCREEN · Seen Oct 2026
- Shortest Path in a Binary MatrixPHONE SCREEN · Seen Sep 2026
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
Meta interview experiences
- Meta PhD SWE Intern AI Coding Phone Screen: 1 Experience
- Meta Business Support Engineer Phone Screen: 1 Experience
- Meta Software Engineer Onsite Questions: 3 Experiences
- Meta AI Native Engineer OA and Onsite: 1 Experience
- Meta AI-Native Coding Interview: 3 Experiences
- Meta Production Engineer Intern Questions: 6 Experiences