FastPrepMax Consecutive Ones III
Problems/Max Consecutive Ones III

Max Consecutive Ones III

InMobi logoInMobi● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an InMobi phone screen. The interview report names and links Max Consecutive Ones III but does not give its full statement or limits. Our version is about 98% the same as the linked task.

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) → int

Examples

Example 1

nums = [1,1,1,0,0,0,1,1,1,1,0]k = 2return = 6

Changing 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 = 3

No changes are allowed, so the existing run of three ones is optimal.

Constraints

  • 1 <= nums.length <= 10^5
  • nums[i] is 0 or 1.
  • 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
All InMobi interview questionsSee InMobi hiring insights
Saved
class Solution {
    public int longestOnes(int[] nums, int k) {
        // write your code here
    }
}
Checking account…