🔥✅✅ Dart Solution 📌📌 || with Explanation 👌👌
Solution
Find the indices of 1 and n: Locate the positions of 1 and n in the array.
Calculate the number of swaps:

The number of swaps required to move 1 to th
# Solution

1. **Find the indices of `1` and `n`:** Locate the positions of `1` and `n` in the array.
2. **Calculate the number of swaps:**
    - The number of swaps required to move `1` to the first position is equal to its current index.
    - The number of swaps required to move `n` to the last position is equal to `(n - 1) - its current index`.
3. **Adjust for Overlap:** If `1` is to the right of `n`, moving `1` to the first position will have already moved `n` one step closer to the last position. Therefore, we need to subtract `1` from the total number of swaps in this case.

### Time Complexity:

- **Finding the indices of `1` and `n`:** This takes `O(n)` time.
- **Calculating the number of swaps:** This is done in constant time `O(1)`.
- **Overall Time Complexity:** `O(n)`.

```dart
class Solution {
  int semiOrderedPermutation(List<int> nums) {
    int n = nums.length;
    int indexOfOne = nums.indexOf(1);
    int indexOfN = nums.indexOf(n);
    int swapsForOne = indexOfOne;
    int swapsForN = (n - 1) - indexOfN;
    if (indexOfOne > indexOfN) {
        return swapsForOne + swapsForN - 1;
    } else {
        return swapsForOne + swapsForN;
    }
  }
}
```
['Dart']