Simple First Thought, One Pass O(n)
Intuition\nGet the first point from where the a[i]{4,5,6,1,3,2}  \n\n# Approach\n Describe your approach to solving the problem. \nGet the first point from wher
# Intuition\nGet the first point from where the a[i]<a[i-1] and increase the count variable\nIf this again happens then return -1, as then the array can never be sorted.\n\nThink about this test case with reference to question, you\'ll see that only one such point should exist for the answer to be not equal to -1.\n\nConsider test case->{4,5,6,1,3,2}  \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nGet the first point from where the a[i]<a[i-1] and increase the count variable which stores no of times this happens.\n\nIf this happens one time only then minmoves=n-i(elements on right to move forward), i.e. the no of elements to the right to be rotated.\n\n# Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(1)\n\n\n# Code\n```\nclass Solution {\n    public int minimumRightShifts(List<Integer> a) {\n        int n=a.size(),minmoves=0,count=0;\n        for(int i=1;i<n;i++){\n            if(a.get(i)<a.get(i-1)){\n                 count++; \n                if(count>1) return -1;\n                minmoves=n-i;\n                \n            }\n        }\n        if(a.get(n-1)>a.get(0) && count!=0) return -1;\n        return minmoves;\n    }\n}\n```
['Java']