Index of 1 and n || simple solution || Java
Code\n\nclass Solution {\n    public int semiOrderedPermutation(int[] nums) {\n        int first = 0, last = 0, n = nums.length;\n        for (int i = 0; i < n;
# Code\n```\nclass Solution {\n    public int semiOrderedPermutation(int[] nums) {\n        int first = 0, last = 0, n = nums.length;\n        for (int i = 0; i < n; i++) {\n           if(nums[i]==1){\n               first=i;\n           }\n            if(nums[i]==n){\n                last=i;\n            }\n        }\n        int min = 0;\n        if(first<last)\n            min = (first + (n-last-1));\n        else\n            min = (first + (n-last-2));\n        return min;\n    }\n}\n```
['Java']