FastPrepMax Consecutive Ones III
Problems/Max Consecutive Ones III

Max Consecutive Ones III

EPAM logoEPAM● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The named exercise gives the whole task. We chose the limits and the function signature. Our version is about 99% the same as the named exercise.

Given a binary array nums and an integer k, you may change at most k zeroes into ones.

Return the maximum length of a contiguous subarray containing only ones after the 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 two zeroes gives a run of six ones.

Example 2

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

Without changes, the longest existing run has length two.

Constraints

  • 1 <= nums.length <= 100000.
  • Each value is 0 or 1.
  • 0 <= k <= nums.length.

Source note: Author-written prompt excerpt retained for source fidelity.

More EPAM Phone Screen questions

  • Longest Palindromic SubstringPHONE SCREEN · Seen Oct 2026
  • Container With Most WaterPHONE SCREEN · Seen Oct 2026
  • Convert an Entry List to a MapPHONE SCREEN · Seen Oct 2026
  • Count Array Element FrequenciesPHONE SCREEN · Seen Oct 2026
  • Find First and Last Position of Element in Sorted ArrayPHONE SCREEN · Seen Oct 2026
  • Group AnagramsPHONE SCREEN · Seen Oct 2026
  • Longest Consecutive SequencePHONE SCREEN · Seen Oct 2026
  • Minimum Currency ConversionsPHONE SCREEN · Seen Oct 2026
  • Next Greater Element IPHONE SCREEN · Seen Oct 2026
  • Partition and Group Values by ParityPHONE SCREEN · Seen Oct 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 IIINykaa · PHONE SCREENNykaa interview questions
  • Disk Space Window AnalyzerAgoda · PHONE SCREENAgoda interview questions
All EPAM interview questionsSee EPAM hiring insights
Saved
class Solution {
    public int longestOnes(int[] nums, int k) {
        // Write your code here.
    }
}
Checking account…