cpp 🤩 | easy solution
Complexity

Time complexity:
O(n)


Space complexity:
O(1)

Code
# Complexity
- Time complexity:
$$O(n)$$

- Space complexity:
$$O(1)$$

# Code
```cpp []
class Solution {
public:
    int semiOrderedPermutation(vector<int>& nums) {

        // Step-1
        // find 1
        int one = -1;
        for (int i = 0; i < nums.size(); ++i) {
            if (nums[i] == 1) {
                one = i;
                break;
            }
        }

        int beforeOne = one - 1;

        int count = 0;
        while (beforeOne != -1) {
            swap(nums[one--], nums[beforeOne--]);
            count++;
        }

        // Step-2
        // find n
        int findn = -1;
        for (int i = 0; i < nums.size(); ++i) {
            if (nums[i] == nums.size()) {
                findn = i;
                break;
            }
        }

        int findnPlus = findn + 1;
        while (findnPlus != nums.size()) {
            swap(nums[findn++], nums[findnPlus++]);
            count++;
        }

        return count;
    }
};
```
['Array', 'Two Pointers', 'C++']