Java Solution - Beats 100% (Using Recursion)
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    private int semiOrder(int nums[], int count) {\n        if(nums[0]==1 && nums[nums.length-1]==nums.length) {\n            return count;\n        }\n        else if(nums[0]==1) {\n            for(int i=0; i<nums.length-1; i++) {\n                if(nums[i]==nums.length) {\n                    nums[i]=nums[i+1];\n                    nums[i+1]=nums.length;\n                    break;\n                }\n            }\n        }\n        else {\n            for(int i=1; i<nums.length; i++) {\n                if(nums[i]==1) {\n                    nums[i]=nums[i-1];\n                    nums[i-1]=1;\n                    break;\n                }\n            }\n        }\n        return semiOrder(nums,count+1);\n    }\n\n    public int semiOrderedPermutation(int[] nums) {\n        return semiOrder(nums, 0);\n    }\n}\n```
['Java']