2855. Minimum Right Shifts to Sort the Array
Problem Statement
You are given a 0-indexed array nums
of length n
containing distinct positive integers. Return the minimum number of right shifts required to sort nums
and -1
if this is not possible.
A right shift is defined as shifting the element at index i
to index (i + 1) % n
, for all indices.
Example 1:
Example 2:
Example 3:
Constraints:
1 <= nums.length <= 100
1 <= nums[i] <= 100
nums
contains distinct integers.
Intuition
Links
https://leetcode.com/problems/minimum-right-shifts-to-sort-the-array/description/
Video Links
Approach 1:
C++
Approach 2:
C++
Approach 3:
C++
Approach 4:
C++
Similar Problems
https://leetcode.com/problems/check-if-array-is-sorted-and-rotated/
Last updated