c++ easy Solution
The given code represents a solution in C++ for the problem of finding the number of operations required to transform a given permutation of integers into a sem
The given code represents a solution in C++ for the problem of finding the number of operations required to transform a given permutation of integers into a semi-ordered permutation.\nThe variable n is assigned the size of the nums vector, which represents the length of the permutation.\n\nThe variables s and e are initialized to 0. These variables will track the indices of the first occurrence of 1 and the last occurrence of n, respectively\n\nAfter the loop, the variable diff is calculated as the difference between the total length of the permutation n and the index of the last occurrence of n e. This represents the number of elements that need to be moved to the left to transform the permutation into a semi-ordered permutation.\n\nThe variable diff is decremented by 1 to exclude the element at index e from the count of operations since it is already in its correct position.\n\nThe variable ans is calculated by adding the index of the first occurrence of 1 s and the adjusted diff. This represents the final position of the last element in the semi-ordered permutation.\n\nIf s is greater than e, it means that the first occurrence of 1 appears after the last occurrence of n. In this case, ans is decremented by 1 to account for this overlap between the two elements.\n```\nclass Solution {\npublic:\n    int semiOrderedPermutation(vector<int>& nums) {\n    int n = nums.size();\n        int s=0;\n        int e=0;\n        for (int i = 0 ; i<n;i++){\n            int val = nums[i];\n            if(val ==1 ||val==n){\n                if (val == 1){\n                    s = i;\n                }\n                else {\n                    e  = i;\n                }\n            }\n        }\n        int diff = n - e;\n        diff--;\n        int ans = s + diff;\n        if(s>e){\n            ans--;\n        }\n        return ans;\n    }\n};\n```
['C++']