Minimum Right Shifts to Sort the Array

Problem Overview

  • Determine the minimum number of right circular shifts needed to make a 0-indexed array of distinct positive integers sorted in ascending order, or return -1 if impossible.
  • Input: int[] nums with 1 <= n <= 100 and 1 <= nums[i] <= 100; Output: an integer shift count or -1.
  • A right shift moves every element one position right with wrap-around (circular shift).
  • Context: array rotation and sorting in cyclic data alignment scenarios.
  • Source: Uber interviews; a common coding interview problem and interview question.

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Input Variables
Execution Result: