simple code C++
\n# Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(1)\n Add your space complexity here, e.g. O(n) \n\n
\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int semiOrderedPermutation(vector<int>& nums) {\n        int start,end;\n        int n = nums.size();\n        for(int i = 0; i<nums.size(); i++){\n            if(nums[i] == 1)\n                start = i;\n            if(nums[i] == n)\n                end = i;\n        }\n        if(start > end)\n            return start + n - end - 2;\n        else \n            return start + n - end-1;\n    }\n};\n```
['C++']