Cool 3 to 1 line solution
Intuition\n Describe your first thoughts on how to solve this problem. \nCalculate the index of 1 and n (they are also the steps needed to get to the edge)\nThe
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nCalculate the index of 1 and n (they are also the steps needed to get to the edge)\nThen if 1 is after n in the array subtract one, because the swap would move n closer to the end. Like this 2413 -> 2143 (distance from 4 to the end was 2 and now its 1 thanks to the swap)\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Code\n```csharp []\npublic class Solution {\n    public int SemiOrderedPermutation(int[] nums) {\n        int index1 = Array.IndexOf(nums,1);\n        int indexN = Array.IndexOf(nums,nums.Length);\n        return index1 + nums.Length-1 - indexN + ((index1 > indexN)?-1:0);\n\n        /* Its also possible in one line, but you have to call IndexOf 2 more times (pretty expensive(but also cool)))\n        return Array.IndexOf(nums,1) + (nums.Length-1) - Array.IndexOf(nums,nums.Length)\n         - ((Array.IndexOf(nums,1) > Array.IndexOf(nums,nums.Length))?1:0);\n        */\n    }\n}\n```
['C#']