Maximum Consecutive Ones in a Circular Array
Updated
Problem statement
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) → intExamples
Example 1
nums = [1,0,1,1,0]k = 1return = 4Flipping the final zero joins the suffix and prefix for four consecutive ones.
Example 2
nums = [0,0,1]k = 1return = 2One zero can be flipped, producing a circular run of two but not three.
Constraints
1 <= nums.length <= 200000- Each value is
0or1. 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