FastPrepMinimum Moves Around a Circular Array
Problems/Minimum Moves Around a Circular Array

Minimum Moves Around a Circular Array

Vanguard logoVanguard● EasyINTERNOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The report describes walking around a circular array but leaves out its exact goal and movement rules. Our version defines a target index and moves of one step in either direction. It is about 40% the same as the reported question for the details they share.

A circular array has n positions indexed from 0 to n - 1. You start at index startIndex and want to reach index targetIndex.

In one move, you may go to either neighboring position:

  • Move right from index i to (i + 1) % n.
  • Move left from index i to (i - 1 + n) % n.

Return the minimum number of moves needed to reach targetIndex. If you already start at the target, return 0.

Only positions matter; the contents of the array do not affect movement.

Function

minimumCircularMoves(n: int, startIndex: int, targetIndex: int) → int

Examples

Example 1

n = 5startIndex = 0targetIndex = 4return = 1

One left move wraps directly from index 0 to index 4. Moving right would take four moves.

Example 2

n = 7startIndex = 2targetIndex = 5return = 3

The shortest route is 2 → 3 → 4 → 5, which takes three moves. The other direction takes four moves.

Example 3

n = 1startIndex = 0targetIndex = 0return = 0

The starting position is already the target, so no move is needed.

Constraints

  • 1 <= n <= 10^9
  • 0 <= startIndex < n
  • 0 <= targetIndex < n

More Vanguard Online Assessment questions

  • Two SumOA · Seen Sep 2026
  • Valid ParenthesesOA · Seen Sep 2026
  • Are They PangramsOA · Seen Nov 2025
  • Missing WordsOA · Seen Nov 2025
  • Spam DetectionOA · Seen Nov 2025
  • Binge WatchingOA · Seen Jan 2023
  • Maximum Occurring CharacterOA · Seen Mar 2022
  • Picking TicketsOA · Seen Mar 2022
  • Tool List: Two Smallest ValuesOA · Seen Nov 2021
  • Group AnagramsOA · Seen Nov 2019

Similar questions at other companies

  • Count Valid Square PairsAuxoAI · OA
  • Picked Player Who LostSusquehanna International Group (SIG) · OASusquehanna International Group (SIG) interview questions
  • Server InvestmentRippling · OARippling interview questions
  • Basic Item DiscountsPalantir · OAPalantir interview questions
  • Next Pascal Row CoefficientIntuit · OAIntuit interview questions
  • Unique Integers That Sum to ZeroNVIDIA · OANVIDIA interview questions
  • Count Multiples of Three with Two SevensHudson River Trading · OAHudson River Trading interview questions
  • Diagonal Bounce TraversalAutodesk · OAAutodesk interview questions
  • Maximum Student-Teacher DistanceChubb · OAChubb interview questions
  • Maximum Three-Server Difficulty ScoreVisa · OAVisa interview questions

Interview reports that mention this question

  • Vanguard Tech and Risk Older OAs: 12 Experiences (Part 3 of 3)
  • Vanguard Software Older Rounds: 13 Experiences (Part 2 of 3)
  • Vanguard Tech Intern Interviews: 37 Experiences (Part 1 of 3)
All Vanguard interview questionsSee Vanguard hiring insights
Saved
class Solution {
    public int minimumCircularMoves(int n, int startIndex, int targetIndex) {
        // Write your code here.
    }
}
Checking account…