[C++/Java] Determining the Positions of 1 and N
\nDetermine the locations of 1 and N, labelled as one_index and n_index respectively. The number of swaps needed to reposition 1 at the start is equivalent to o
\nDetermine the locations of `1` and `N`, labelled as `one_index` and `n_index` respectively. The number of swaps needed to reposition `1` at the start is equivalent to `one_index`, and similarly, to move `N` to the final position, `N - 1 - n_index` swaps are required. \n\nHowever, should `1` be located to the right of `N`, then as `1` is moved towards the 0th position, it would swap places with `N`, thereby bringing `N` a step closer to its desired final position. This would therefore require one less swap, i.e., `N - 1 - n_index - 1` to relocate `N` to the end. Consequently, if `1` is to the right of `N`, we need to subtract 1 from the total swap count.\n\nC++:\n```\nclass Solution {\npublic:\n    int semiOrderedPermutation(vector<int>& nums) {\n        int n = nums.size();\n        int one_index = 0, n_index = 0;\n        for (int i = 0; i < n; i++) {\n            if (nums[i] == 1) one_index = i;\n            else if (nums[i] == n) n_index = i;\n        }\n        return one_index + n - 1 - n_index - (one_index < n_index ? 0 : 1);\n    }\n};\n```\n\nJava:\n```\nclass Solution {\n    public int semiOrderedPermutation(int[] nums) {\n        int n = nums.length;\n        int oneIndex = 0, nIndex = 0;\n        for (int i = 0; i < n; i++) {\n            if (nums[i] == 1) oneIndex = i;\n            else if (nums[i] == n) nIndex = i;\n        }\n        return oneIndex + n - 1 - nIndex - (oneIndex < nIndex ? 0 : 1);\n    }\n}\n```
['C', 'Java']