FastPrepMaximum Consecutive Ones in a Circular Array
Problems/Maximum Consecutive Ones in a Circular Array

Maximum Consecutive Ones in a Circular Array

LinkedIn logoLinkedIn● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a LinkedIn onsite interview. The report names a task about the longest run of a target value, with no limits or changes given. Here, we keep our existing version. It uses a circular binary array, at most k zero flips, and at most one lap. The report does not confirm that the array is circular, the flip budget, turning the named target into a binary array, the limits or the function signature. Those are our choices. Our version is about 65% the same as the reported question.

Given a circular binary array nums, you may change at most k zeros to ones. Return the maximum number of consecutive ones on the circle after those changes.

A circular segment may wrap from the end to the beginning, but it may contain each array position at most once, so its length never exceeds nums.length.

Function

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

Examples

Example 1

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

Flipping the final zero joins the suffix and prefix for four consecutive ones.

Example 2

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

One zero can be flipped, producing a circular run of two but not three.

Constraints

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

More LinkedIn Onsite Interview questions

  • Allocate Mailboxes with Squared DistanceONSITE INTERVIEW · Seen Nov 2026
  • Find Leaves of a Binary TreeONSITE INTERVIEW · Seen Nov 2026
  • Max Points on a LineONSITE INTERVIEW · Seen Nov 2026
  • 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
  • Longest Binary Window with at Most K OnesONSITE INTERVIEW · Seen Oct 2026
  • LRU Cache OperationsONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Maximum Earnings Across WarehousesAmazon · ONSITE INTERVIEW
  • Shortest Window with Required CountsOracle · ONSITE INTERVIEWOracle interview questions
  • Count Zero Request ServersSalesforce · ONSITE INTERVIEWSalesforce interview questions
  • Longest Subarray Within an Absolute-Difference LimitGoogle · ONSITE INTERVIEWGoogle interview questions
  • Max Consecutive Ones IIIMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Longest Continuous Subarray Within an Absolute-Difference LimitUber · ONSITE INTERVIEWUber interview questions
  • Sliding-Window Rate LimiterSnowflake · ONSITE INTERVIEWSnowflake interview questions
  • Count Equal Code Pairs Within Distance KInfosys · ONSITE INTERVIEWInfosys interview questions
  • Maximize Element FrequencyGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • Longest Subarray with At Most Two Distinct ValuesMoody's Investors Service · ONSITE INTERVIEW

LinkedIn interview experiences

  • LinkedIn Senior MLE Interview Questions: 1 Experience
  • 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 longestCircularOnes(int[] nums, int k) {
        // Write your code here.
    }
}
Checking account…