Sorting | C++ | Easy to understand
Intuition\n Describe your first thoughts on how to solve this problem. \nIf from the minimum value present in the input array, we compare each element from the 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIf from the minimum value present in the input array, we compare each element from the current array to an array which is sorted with the same elements present in it and if they are in the same order then we return number of right shifts otherwise -1,\n\n# Complexity\n- Time complexity: O(n logn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int minimumRightShifts(vector<int>& nums) {\n        int n = nums.size();\n        int ir = 200;\n        int ans = -1;\n        for(int i = 0; i < n; i++){\n            if(nums[i] < ir){\n                ir = nums[i];\n                ans = i;\n            }\n        }\n        vector<int> temp = nums;\n        int  x = ans;\n        sort(temp.begin(), temp.end());\n        for(int i = 0; i < n;i ++){\n            if(temp[i] != nums[(x + i) % n])\n                return -1;\n        }\n        if(ans == 0)\n            return ans;\n        else\n            return n - ans;\n    }\n};\n```
['Sorting', 'C++']