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 moves = 0;\n        int pos1 = -1;\n        int posn = -1;\n        for(int i=0; i<nums.length; i++)\n        {\n            if(nums[i] == 1)\n            {\n                pos1 = i;\n            }\n            if(nums[i] == nums.length)\n            {\n                posn = i;\n            }\n        }\n        moves = pos1 + nums.length-1 - posn;\n        if(posn>pos1) return moves;\n        else return moves-1;\n    }\n}\n```
['Java']