✅Easy Solution🔥C++/Java🔥
\n\n\n# Approach\n Describe your approach to solving the problem. \n\nPretty straight forward problem. Find index of minimum element. Then check if is valid to 
![ff4bc0ef-8a8a-4d63-8797-9336739e6ca5_1693111536.0989811.png](https://assets.leetcode.com/users/images/3306fdb8-c0bf-4fde-acbb-0e1d12780cbf_1694884688.9199002.png)\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\nPretty straight forward problem. Find index of minimum element. Then check if is valid to rotate, return -1 in the invalid cases, otherwise return (n - index)%n.\n\n# Code\n\n```Java []\nclass Solution {\n    public int minimumRightShifts(List<Integer> nums) {\n        int min = 101;\n        int ind = 0;\n        for(int i=0; i<nums.size(); i++){\n            if(nums.get(i) < min){\n                min = nums.get(i);\n                ind = i;\n            }\n        }\n        \n        int last = min;\n        for(int i=ind + 1; i < nums.size(); i++){\n            if(nums.get(i) < last){\n                return -1;\n            }\n            last = nums.get(i);\n        }\n        \n        for(int i=0; i<ind; i++){\n            if(nums.get(i) < last){\n                return -1;\n            }\n            last = nums.get(i);\n        }\n        \n        int mov = nums.size() - ind;\n        return mov % nums.size();\n    }\n}\n```\n```C++ []\nclass Solution {\npublic:\n    int minimumRightShifts(vector<int>& nums) {\n        int min = 101;\n        int ind = 0;\n        \n        for (int i = 0; i < nums.size(); i++) {\n            if (nums[i] < min) {\n                min = nums[i];\n                ind = i;\n            }\n        }\n        \n        int last = min;\n        \n        for (int i = ind + 1; i < nums.size(); i++) {\n            if (nums[i] < last) {\n                return -1;\n            }\n            last = nums[i];\n        }\n        \n        for (int i = 0; i < ind; i++) {\n            if (nums[i] < last) {\n                return -1;\n            }\n            last = nums[i];\n        }\n        \n        int mov = nums.size() - ind;\n        return mov % nums.size();\n    }\n};\n\n```\n\n\n
['Array', 'Sorting', 'C++', 'Java']