2 C++ solutions || Beginner-friendly approach || With and without vector.find()
\n# Code\n\n// Soution 1 (With find())\nclass Solution {\npublic:\n    int semiOrderedPermutation(vector<int>& A) {\n        int n = A.size();\n        int i = 
\n# Code\n```\n// Soution 1 (With find())\nclass Solution {\npublic:\n    int semiOrderedPermutation(vector<int>& A) {\n        int n = A.size();\n        int i = find(A.begin(), A.end(), 1) - A.begin(); \n        int j = find(A.begin(), A.end(), n) - A.begin();\n        return i + n - 1 - j - (i > j);\n    }\n}\n\n// Solution 2 (Without find())\nclass Solution {\npublic:\n    int semiOrderedPermutation(vector<int>& nums) {\n        int n=nums.size(), count=0;\n        for(int i=0; i<n; i++)\n        {\n            if(nums[i]==1){\n                count+=i;\n                for(int j=i; j>0; j--)\n                    swap(nums[j], nums[j-1]); // we swap the numbers so that the later considering the case when 1 comes after n-1 because count will get repeated for such cases\n                break;\n            }\n        }\n        for(int i=0; i<n; i++)\n        {\n            if(nums[i]==n){ \n                count+=(n-1)-i;\n                break;\n            }\n        }\n        return count;\n    }\n};\n```
['C++']