Reported December 2025
Motivesliding window

Minimum Swaps to Group Circular Ones

Reported by candidates from Motive's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Motive OA. Under 2s to a working solution.
Founder's read

The array is circular, and that single word is what makes this Motive OA question from December 2025 trickier than it looks. You're given a binary array and asked for the fewest swaps between any two positions to group every 1 into one contiguous block, wrapping around the end. The hinted tag says hash-table, but the real pattern is a fixed-size sliding window. If you've seen it, it's five minutes. If you haven't, the wraparound will eat your clock. StealthCoder is the safety net if your mind goes blank mid-assessment.

The problem

Given a circular binary array nums, return the minimum number of swaps between any two positions needed to group all 1s into one contiguous circular block.

Function
minSwapsCircularOnes(nums: int[]) → int

Examples
Example 1
nums = [0,1,0,1,1,0,0]
return = 1
Example 2
nums = [1,1,0,0,1]
return = 0

Constraints
1 <= nums.length <= 100000.
Every value is 0 or 1.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Count the total ones, call it k. The final block is a window of length k, so the answer is the minimum number of zeros inside any circular window of size k. Each zero in the window needs exactly one swap with a one outside it. Slide the window across the array and track zeros as you add and drop elements. For the circular part, use index i mod n, or concatenate the array with itself and scan windows starting at 0 to n-1. Common pitfalls: forgetting the wraparound, so example 1 gives the wrong answer on edge windows, and not handling k = 0 or k = n, where the answer is 0. Don't reach for a hash table here, it adds nothing. Runtime is O(n) with O(1) extra space, which matters at 100000 elements. If the window logic slips under pressure, StealthCoder can hand you the working solution live.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Minimum Swaps to Group Circular Ones cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as minimum swaps to group all 1s together ii. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Motive's OA.

Motive reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Minimum Swaps to Group Circular Ones FAQ

What's the trick to Minimum Swaps to Group Circular Ones?+

Count the ones, k. Then find the circular window of length k with the fewest zeros. That zero count is your swap count, since each zero gets swapped with a one sitting outside the window. It's a fixed-size sliding window, not a hashing problem.

Why is the hinted pattern hash-table if it's really a sliding window?+

The hint is just a loose tag. Nothing here needs key lookups. You only need a running count of zeros in a window. Don't force a map into it. A single pass with a counter is cleaner and faster.

How do I handle the circular part?+

Either index with (i mod n) while sliding the window, or conceptually double the array and check windows starting at each index from 0 to n-1. Both give the same result. The modulo approach keeps memory at O(1).

What edge cases should I test?+

All zeros, all ones, a single element, and a case where the best window wraps around the end. When k is 0 or n, the answer is 0. Example 2, [1,1,0,0,1], returns 0 because the ones already group circularly.

How do I prepare for this in 48 hours?+

Solve the fixed-size sliding window pattern a few times, then do one circular variant. Write the zero-count update by hand: add the new element, drop the old one. Dry-run both examples. That's enough for this problem.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Motive.

OA at Motive?
Invisible during screen share
Get it