FastPrepLongest Binary Window with at Most K Ones
Problems/Longest Binary Window with at Most K Ones

Longest Binary Window with at Most K Ones

LinkedIn logoLinkedIn● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report states the task of the longest window with at most K ones. It does not give limits or say what to do with empty input. Our version is about 98% the same as the reported question.

Given a binary array nums and a nonnegative integer k, return the length of the longest contiguous subarray containing at most k ones.

The limit counts values equal to 1. Zeros do not use that limit. Return 0 for an empty array or when no nonempty subarray is valid.

Function

longestBinaryWindow(nums: int[], k: int) → int

Examples

Example 1

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

The subarray at indices 2 through 5 is [0,0,1,0]. It has one 1 and length 4. Every subarray of length 5 has at least two ones.

Example 2

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

With no ones allowed, the longest run of zeros is [0,0], of length 2.

Example 3

nums = []k = 0return = 0

The empty array has no nonempty subarray, so the result is 0.

Constraints

  • 0 <= nums.length <= 100000.
  • Every nums[i] is 0 or 1.
  • 0 <= k <= nums.length.

More LinkedIn Onsite Interview questions

  • Explore an Unknown Grid and Find a PathONSITE INTERVIEW · Seen Nov 2026
  • Fire Station Response BillONSITE INTERVIEW · Seen Nov 2026
  • Roll a Weighted DieONSITE INTERVIEW · Seen Oct 2026
  • Longest Binary Subarray With at Most K OnesONSITE INTERVIEW · Seen Oct 2026
  • Kth Closest Element in a BSTONSITE INTERVIEW · Seen Oct 2026
  • LRU Cache OperationsONSITE INTERVIEW · Seen Oct 2026
  • Lexicographically Smallest Course OrderONSITE INTERVIEW · Seen Oct 2026
  • K Closest Values in a Binary Search TreeONSITE INTERVIEW · Seen Oct 2026
  • Unique Single-Use Sum CombinationsONSITE INTERVIEW · Seen Oct 2026
  • Maximum Consecutive Ones in a Circular ArrayONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Shortest Window with Required CountsOracle · ONSITE INTERVIEWOracle interview questions
  • Trim a Telemetry Buffer to a Target SumAmazon · ONSITE INTERVIEW
  • Count Hotspot Playback WindowsGoogle · ONSITE INTERVIEWGoogle interview questions
  • Subarray with a Given SumExpedia · ONSITE INTERVIEWExpedia 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
  • Count Subarrays With Product Equal to KSalesforce · OASalesforce interview questions
  • Max Consecutive Ones IIINykaa · PHONE SCREENNykaa interview questions
  • Maximum Consecutive Sum Within a ThresholdIndeed · OAIndeed interview questions

LinkedIn interview experiences

  • LinkedIn Staff AI Engineer Phone Screens: 1 Experience
  • LinkedIn Experienced MLE Onsite: 1 Experience
  • LinkedIn Coding with AI Interview: 4 Experiences
  • LinkedIn Experienced Infrastructure SWE Onsite: 1 Experience
All LinkedIn interview questionsSee LinkedIn hiring insights
Saved
class Solution {
    public int longestBinaryWindow(int[] nums, int k) {
        // write your code here
    }
}
Checking account…