Kotlin Straightforward Solution
Code
# Code
```kotlin []
class Solution {
    fun semiOrderedPermutation(nums: IntArray): Int {
        val (indexOne, indexN) = arrayOf(nums.indexOf(1), nums.indexOf(nums.size))
        val res = indexOne + (nums.size - indexN - 1)
        return res - if (indexOne >= indexN) 1 else 0
    }
}

```
['Kotlin']