beats 100% .Simple approach
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n    public int semiOrderedPermutation(int[] nums) {\n        int cost = 0 ;\n        int n = nums.length;\n        int min = Integer.MAX_VALUE;\n        int max = Integer.MIN_VALUE;\n        int minPos = -1;\n        int maxPos = -1;\n        for(int i=0;i<n;i++){\n\n            if(nums[i]<min){\n                min = nums[i];\n                minPos = i;\n            }\n\n            if(nums[i]>max){\n                max = nums[i];\n                maxPos = i;\n            }\n           \n        }\n        if(minPos>maxPos){\n            return (minPos-0) + (n-maxPos-1) -1;\n        }\n        return (minPos-0) + (n-maxPos-1);\n        \n    }\n}\n```
['Java']