Minimum Number of Operations to Reinitialize a Permutation Solution in C++
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)$$ -->\nO(n*m)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(n)\n# Code\n```\nclass Solution {\npublic:\n    int reinitializePermutation(int n) {\n        int i, count=1;\n        vector<int> initial_arr;\n        vector<int> temp;\n        vector<int> new_arr;\n        for(i=0 ; i<n ; i++)\n        {\n            initial_arr.push_back(i);\n        }\n        for(i=0 ; i<n ; i++)\n        {\n            if(i%2==0)\n            {\n                new_arr.push_back(initial_arr[i/2]);\n                temp.push_back(initial_arr[i/2]);\n            }\n            else\n            {\n                new_arr.push_back(initial_arr[n/2 + (i-1)/2]);\n                temp.push_back(initial_arr[i/2]);\n            }\n        }\n        if(new_arr==initial_arr)\n        {\n            return 1;\n        }\n        while(true)\n        {\n            for(i=0 ; i<n ; i++)\n            {\n                if(i%2==0)\n                    temp[i] = new_arr[i/2];\n                else\n                    temp[i] = new_arr[n/2 + (i-1)/2];\n            }\n            new_arr.clear();\n            copy(temp.begin(), temp.end(), back_inserter(new_arr));\n            count++;\n            if(new_arr==initial_arr)\n                break;\n        }\n        return count;\n    }\n};\n```\n![upvote new.jpg](https://assets.leetcode.com/users/images/82263beb-f171-4de8-b687-a92bd8c79a38_1684123226.1984327.jpeg)\n
['C++']