a few solutions
Peform the simulation via a double-ended-queue D and return the total t rotations needed until the input array A is sorted.\n\n---\n\nKotlin\n\nclass Solution {
Peform the simulation via a double-ended-queue `D` and return the total `t` rotations needed until the input array `A` is sorted.\n\n---\n\n*Kotlin*\n```\nclass Solution {\n    fun minimumRightShifts(A: List<Int>): Int {\n        var D = ArrayDeque(A)\n        var ok = { D.withIndex().all{ (i, _) -> (0 < i && D[i - 1] < D[i]) || i == 0 } }\n        var (t, N) = Pair(0, A.size)\n        while (!ok() && t < N) {\n            D.addFirst(D.removeLast()); ++t\n        }\n        return if (t < N) t else -1\n    }\n}\n```\n\n*Javascript*\n```\nlet minimumRightShifts = (A, N = A.length, ok = () => A.every((_, i) => 0 < i && A[i - 1] < A[i] || !i), t = 0) => {\n    while (!ok() && t < N)\n        A.unshift(A.pop()), ++t;\n    return t < N ? t : -1;\n};\n```\n\n*Python3*\n```\nclass Solution:\n    def minimumRightShifts(self, A: List[int]) -> int:\n        ok = lambda: all(A[i - 1] < A[i] for i in range(1, len(A)))\n        A, t, N = deque(A), 0, len(A)\n        while not ok() and t < N:\n            A.appendleft(A.pop()); t += 1\n        return t if t < N else -1\n```\n\n*Rust*\n```\nuse std::collections::VecDeque;\nimpl Solution {\n    pub fn minimum_right_shifts(A: Vec<i32>) -> i32 {\n        let N = A.len();\n        let mut D = VecDeque::from(A);\n        let mut t = 0;\n        while t < N {\n            let mut ok = true;\n            for i in 1..N {\n                if !(D[i - 1] <= D[i]) {\n                    ok = false;\n                    break;\n                }\n            }\n            if ok {\n                return t as i32;\n            }\n            let back = D.pop_back().unwrap(); D.push_front(back); t += 1;\n        }\n        -1\n    }\n}\n```\n\n*C++*\n```\nclass Solution {\npublic:\n    using VI = vector<int>;\n    using Deque = deque<int>;\n    int minimumRightShifts(VI& A, int t = 0) {\n        int N = A.size();\n        Deque D{ A.begin(), A.end() };\n        while (!is_sorted(D.begin(), D.end()) && t < N)\n            D.push_front(D.back()), D.pop_back(), ++t;\n        return t < N ? t : -1;\n    }\n};\n```
[]