Semi-ordered-permutation(In Java with Explaination and Example)
Explaination
Find the positions of 1 and n in the array (x and y).
The position of 1 in nums (let's call it x).
The position of n in nums (let's call it y).
Cal
# Explaination
- Find the positions of 1 and n in the array (x and y).
The **position of 1** in nums (let's call it x).
The **position of n** in nums (let's call it y).
- Calculate the swaps as:
If x < y: Total swaps = x + (n - 1 - y).
If x > y: Total swaps = x + (n - 1 - y) - 1.
# Examples

Input: nums = [2, 1, 4, 3]
pos1 = 1 (position of 1).
posN = 3 (position of 4).

Calculations:
Swaps to move 1 to the start: pos1 = 1.
Swaps to move n to the end: (n - 1 - posN) = 4 - 1 - 3 = 0.
Total swaps: 1 + 0 = 2.
**Output: 2.**

# Code
```java []
class Solution {
    public int semiOrderedPermutation(int[] nums) {
        int n = nums.length;
        int x = nums[0],y=nums[0];

        for(int i=0;i<n;i++){
            if(nums[i]==1){
                x=i;
            }
            if(nums[i]==n){
                y=i;
            }
        }
        if(x<y){
            return x+(n-y-1);
        }
        else{
            return x+(n-y-1)-1;
        }
    }
}
```
['Java']