FastPrepMax Consecutive Ones III
Problems/Max Consecutive Ones III

Max Consecutive Ones III

Nykaa logoNykaa● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Nykaa phone screen for a full-time role. The report points to this algorithm exercise. We chose the function interface, the limits, fixed rules, and the examples.

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

Examples

Example 1

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

Flipping two zeros creates a six-element run.

Example 2

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

Without flips, the central run has length three.

Example 3

nums = [0,0,0]k = 3return = 3

All three zeros can be flipped.

Constraints

  • 0 ≤ nums.length ≤ 100000.
  • Every value in nums is 0 or 1.
  • 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
All Nykaa interview questionsSee Nykaa hiring insights
Saved
class Solution {
    public int longestOnes(int[] nums, int k) {
        // write your code here
    }
}
Checking account…