O(n) || Very easy || Java
Approach\n Describe your approach to solving the problem. \n    Just find the idex of 1 and the index of maximum number. \n    If the index of 1 > index of max 
# Approach\n<!-- Describe your approach to solving the problem. -->\n    Just find the idex of 1 and the index of maximum number. \n    If the index of 1 > index of max number, it will take one swap less \n    if(idx1>idx){\n        idx1=idx1-1;\n        }\n    The answer will be (nums.length-1-idx) + idx1\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n    O(n)\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n    O(1)\n\n# Code\n```\nclass Solution {\n    public int semiOrderedPermutation(int[] nums) {\n        int max=Integer.MIN_VALUE;\n        int idx=0,idx1=0;\n        for(int i=0;i<nums.length;i++){\n            if(nums[i]>max){\n                max=nums[i];\n                idx=i;\n            }\n            if(nums[i]==1){\n                idx1=i;\n            }\n        }\n        if(idx1>idx){\n            idx1=idx1-1;\n        }\n        return (nums.length-1-idx) + idx1;\n    }\n}\n```
['Java']