2855. Minimum Right Shifts to Sort the Array
Problem Statement
Input: nums = [3,4,5,1,2]
Output: 2
Explanation:
After the first right shift, nums = [2,3,4,5,1].
After the second right shift, nums = [1,2,3,4,5].
Now nums is sorted; therefore the answer is 2.Input: nums = [1,3,5]
Output: 0
Explanation: nums is already sorted therefore, the answer is 0.Input: nums = [2,1,4]
Output: -1
Explanation: It's impossible to sort the array using right shifts.Intuition
Links
Video Links
Approach 1:
Approach 2:
Approach 3:
Approach 4:
Similar Problems
Last updated