[Java/C++/Python] Index of 1 and n
Explanation\nIf index of 1 is i,\n1 needs i swaps to be the first.\n\nIf index of n is j,\nn needs n - 1 - j swaps to be the first.\n\nIf i < j,\nres is i + (n 
# **Explanation**\nIf index of `1` is `i`,\n`1` needs `i` swaps to be the first.\n\nIf index of `n` is `j`,\n`n` needs `n - 1 - j` swaps to be the first.\n\nIf `i < j`,\n`res` is `i + (n - 1 - j)`.\n\nIf `i > j`,\n`res` is `i + (n - 1 - j) - 1`,\nsave one swap when swap `1` and `n`.\n<br>\n\n# **Complexity**\nTime `O(n)`\nSpace `O(1)`\n<br>\n\n**Java**\n```java\n    public int semiOrderedPermutation(int[] A) {\n        int n = A.length, i = 0, j = 0;\n        for (int k = 0; k < n; k++) {\n            if (A[k] == 1) i = k;\n            if (A[k] == A.length) j = k;\n        }\n        return i + n - 1 - j - (i > j ? 1 : 0);\n    }\n```\n\n**C++**\n```cpp\n    int semiOrderedPermutation(vector<int>& A) {\n        int n = A.size(), i = find(A.begin(), A.end(), 1) - A.begin(), j = find(A.begin(), A.end(), n) - A.begin();\n        return i + n - 1 - j - (i > j);\n    }\n```\n\n**Python**\n```py\n    def semiOrderedPermutation(self, A: List[int]) -> int:\n        n = len(A)\n        i, j = A.index(1), A.index(n)\n        return i + n - 1 - j - (i > j)\n```\n
['C', 'Python', 'Java']