FastPrepMinimum Swaps to Group Circular Ones
Problems/Minimum Swaps to Group Circular Ones

Minimum Swaps to Group Circular Ones

Motive logoMotive● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A firsthand Motive onsite report for a full-time role names a well-known problem about the fewest swaps needed to group all the ones together in a circular array.

Our version is about 99% the same as the reported question.

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.

More Motive Onsite Interview questions

  • Group AnagramsPHONE SCREEN · ONSITE INTERVIEW · Seen Jan 2026
  • Longest Equal-Zero-One SubarrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jan 2026
  • Maximum Weighted Sum After Left RotationsONSITE INTERVIEW · Seen Jan 2026
  • Valid Parenthesis StringPHONE SCREEN · ONSITE INTERVIEW · Seen Jan 2026
  • Best Time to Buy and Sell StockONSITE INTERVIEW · Seen Dec 2025
  • Target Triplet SumONSITE INTERVIEW · Seen Dec 2025
  • Validate IP AddressONSITE INTERVIEW · Seen Dec 2025
  • Generate Palindromic PermutationsONSITE INTERVIEW · Seen Dec 2025
  • Staircase Search In A Sorted MatrixONSITE INTERVIEW · Seen Dec 2025
  • Search in Rotated Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2025

Similar questions at other companies

  • 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
  • Minimum Swaps to Group Circular OnesAmazon · ONSITE INTERVIEW
  • Longest Binary Subarray With at Most K OnesLinkedIn · ONSITE INTERVIEWLinkedIn 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
All Motive interview questionsSee Motive hiring insights
Saved
class Solution {
    public int minSwapsCircularOnes(int[] nums) {
      // write your code here
    }
}
Checking account…