java simple Solution
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```\nclass Solution {\n    public int semiOrderedPermutation(int[] nums) {\n        int temp=0;\n        int temp2=0;\n        for(int i=0;i<nums.length;i++)\n        {\n            if(nums[i]==1)\n            {\n                temp=i;\n            }\n            else if(nums[i]==nums.length)\n            {\n                temp2=i;\n            }\n        }\n        int sum=0;\n        if(temp2>temp)\n        {\n           sum=(nums.length-1-temp2)+temp;\n        }\n        else\n        {\n            sum=temp+(nums.length-2-temp2);\n        }\n        \n    return sum;\n    }\n}\n```
['Java']