i/p o/p analyze kro ho jayega  :D
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```cpp []\nclass Solution {\npublic:\n    int semiOrderedPermutation(vector<int>& nums) {\n        int n=nums.size();\n        if(nums[0]==1&&nums[n-1]==n)\n           return 0;\n\n        auto it=find(nums.begin(),nums.end(),1);\n        int i=distance(nums.begin(),it);\n        \n        it=find(nums.begin(),nums.end(),n);\n        int j=distance(nums.begin(),it);\n\n        if(i<j)\n        {\n            return (i-0)+(n-1-j);\n        }\n        else if(i>j)\n        {\n             return (i-0)+(n-1-j)-1;\n        }\n\n\n        return -1;\n    }\n};\n```
['C++']