Tap here to switch tabs
Problem
Submissions

Problem: Minimum Right Shifts to Sort the Array

med
30 min
Try to solve the Minimum Right Shifts to Sort the Array problem.

Statement

You are given an array nums consisting of distinct positive integers.

In one right shift operation, the last element of nums is moved to the first position, and all other elements are shifted one position to the right.

Return the minimum number of right shifts needed to sort nums in strictly increasing order. If it is impossible to sort the array using right shifts, return −1-1.

Constraints:

  • 1≤1 \leq nums.length ≤100\leq 100

  • 1≤1 \leq nums[i] ≤100\leq 100

  • nums contains distinct integers.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Right Shifts to Sort the Array

med
30 min
Try to solve the Minimum Right Shifts to Sort the Array problem.

Statement

You are given an array nums consisting of distinct positive integers.

In one right shift operation, the last element of nums is moved to the first position, and all other elements are shifted one position to the right.

Return the minimum number of right shifts needed to sort nums in strictly increasing order. If it is impossible to sort the array using right shifts, return −1-1.

Constraints:

  • 1≤1 \leq nums.length ≤100\leq 100

  • 1≤1 \leq nums[i] ≤100\leq 100

  • nums contains distinct integers.