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
Video Links
Approach 1:
Approach 2:
Approach 3:
Approach 4:
Similar Problems
Last updated