Best Approach ||  C++ || TC : O(n) || SC : O(1) || Easy to understand
Intuition\n\tIn the context of a rotated sorted array, it is a requirement that the elements after the maximum value and the elements before the maximum value a
**Intuition**\n\tIn the context of a rotated sorted array, it is a requirement that the elements after the maximum value and the elements before the maximum value are both sorted.\n**Approach**\n* Find the maximum of the vector and its index\n* Check for edge cases \n* Check left part and right part are sorted or not\n\n**Complexity**\n* Time complexity: **O(n)**\n* Space complexity: **O(1)**\n\n**Code:**\n\n```\nclass Solution {\n     private:\n\t\t // Checking if the left part is sorted or not\n\n        bool LeftCheckSorted(vector<int> &arr,int st,int ed){\n            for(int i=st;i<ed;i++){\n                if(arr[i]>arr[i+1]){\n                    return false;\n                }\n            }\n            return true;\n        }\n\t\t// Checking if the right part is sorted or not\n\t\t\n        int RightCheckSorted(vector<int> &arr,int st,int ed,int &ans){\n            for(int i=st;i<ed-1;i++){\n                if(arr[i]<arr[i+1]){\n                    ans++;\n                }else{\n                    ans=-1;\n                    break;\n                }\n            }\n\t\t\t// Checking if just after the max element the array is ending\n\t\t\t\n            if(st==ed-1) ans++;\n\t\t\t\n\t\t\t// Checking for the last element as the loop works till n-1 so we miss the last element\n\t\t\t\n            else if(ans>0) ans++;\n\t\t\t\n            return ans;\n        }\n       \n    \npublic:\n    int minimumRightShifts(vector<int>& nums) {\n        int idx=0,n=nums.size();\n\t\t\n\t\t// Finding the max element in the vector\n\t\t\n        int maxi=*max_element(nums.begin(),nums.end());\n\t\t\n\t\t// Finding its index (you can combine these steps)\n\t\t\n        for(int i=0;i<n;i++){\n            if(nums[i]==maxi){\n                idx=i;\n                break;\n            }\n        }\n        int ans=0;\n\t\t\n\t\t// Checking if the max element is at the 0 position\n        // In this case, we have to check the right part only\n\t\t\n        if(idx==0){\n            RightCheckSorted(nums,idx+1,n,ans);\n        }\n\t\t\n\t\t// Checking if the max element is at the last position\n        // In this case, we have to check the left part only\n\t\t\n        else if(idx==n-1){\n            if(!LeftCheckSorted(nums,0,idx)){\n                ans=-1;   \n            }\n        }\n\t\t\n\t\t// Checking if the max element is in between the vector\n        // In this case, we have to check the left part and then the right part\n        // because if the left part is sorted, then only we can calculate the shifts we require.\n\t\t\n        else if(LeftCheckSorted(nums,0,idx)){\n            RightCheckSorted (nums,idx+1,n,ans);\n        }\n        else ans=-1;\n        \n        return ans;\n        \n    }\n};\n```\n\n***Up Vote if you understood it***
['C']