Minimum Swaps to Group All 1's Together II
A medium-tier problem at 66% community acceptance, tagged with Array, Sliding Window. Reported in interviews at josh technology and 1 others.
Minimum Swaps to Group All 1's Together II is the circular cousin of a classic sliding window problem. You've got a circular array and need to find the minimum swaps to cluster all 1's into one contiguous block. Josh Technology and IBM both ask this. The acceptance rate sits at 65%, but that masks a specific gotcha: most candidates solve the linear version and then fumble the wraparound logic. If this problem hits your live assessment and you blank on how to handle the circular case, StealthCoder solves it in seconds, invisible to the proctor.
Companies that ask "Minimum Swaps to Group All 1's Together II"
Minimum Swaps to Group All 1's Together II is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Made by a working FAANG engineer who treats the OA the way companies treat hiring: as a game with rules you should know.
Get StealthCoderThe trick is recognizing this as a sliding window problem in disguise. First, count total 1's in the array. That count is your window size. Then slide a window of that size across the circular array, counting 1's in each position. The window that contains the most 1's means you need the fewest swaps to group them all there. The circular part isn't actually hard once you see it: instead of resizing the array or using modulo excessively, just iterate the window across the array twice, or use modulo arithmetic cleanly. Most people get stuck because they try to physically rotate the array or implement a clunky wraparound. The algorithm is Array and Sliding Window, and it's fast. If you haven't practiced circular arrays with sliding window, StealthCoder is the safety net for when you hit this live.
Pattern tags
You know the problem.
Make sure you actually pass it.
Minimum Swaps to Group All 1's Together II recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Made by a working FAANG engineer who treats the OA the way companies treat hiring: as a game with rules you should know. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Minimum Swaps to Group All 1's Together II interview FAQ
Why is this medium and not easy?+
The circular aspect trips up candidates who only know linear sliding window. Once you realize you're finding the best 'window of size K' around a circle, it's mechanical. But that realization takes practice. The acceptance rate of 65% reflects how many people hit that wall.
Do I need to physically rotate the array?+
No. Iterate your window across the array using modulo, or just extend your loop logic to handle wraparound. Physical rotation wastes time and memory. The sliding window operates in O(n) time regardless.
Is this still asked at big tech?+
Josh Technology and IBM both report asking it. It's not as common as classic sliding window problems, but it appears often enough in OAs that you shouldn't skip it if you see it live.
What's the main pitfall on the circular logic?+
Forgetting that the best window might wrap from the end of the array back to the start. If you only check non-wrapping windows, you miss valid groupings. Modulo arithmetic or double-pass iteration both handle this correctly.
How does this differ from the linear version?+
Linear version finds the best contiguous block in a straight array. Circular version allows that block to wrap around the end. Algorithmically identical after you handle the wraparound, but conceptually it trips up candidates who over-complicate the bookkeeping.
Want the actual problem statement? View "Minimum Swaps to Group All 1's Together II" on LeetCode →