C++ || Recursive Simulation || Explained || Brute Force
Intuition\n Describe your first thoughts on how to solve this problem. \nSimulation with the help of RECURSION.  \n# Approach\n Describe your approach to solvin
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSimulation with the help of RECURSION.  \n# Approach\n<!-- Describe your approach to solving the problem. -->\nWe will operate with 3 arrays at a time :\n1. original = original permutation for comparison\n2. vec1 = using as parent permutaion to create new permutaion in following step.\n3. vec2 = the new permutaion formed from vec1.\n\nUsing int val, in each permutation modification step : to check if the new permuation is equal to the original permutation.\n        -> if val=0, original permutaion formed , thus return.\n        -> else if val!=0, call for next recursive modification.\n\nDruing recursive appraoch for next tranformation we interchange vec2 with vec1,  as now this will be the new parent permutation in its child permutation fromation.\n\n\n![download (2).jfif](https://assets.leetcode.com/users/images/cfca5833-1659-4ee6-8dca-95f1cb3fb237_1677168455.339832.jpeg)\n\n\n\n# Complexity\n- Time complexity   :   O(number of modification steps * n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity  :   O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    void func(vector<int> original, vector<int> &vec1, vector<int> &vec2, int &cnt, int n)   {\n        //variable for comparing original with next permutaion formed\n        int val=0;\n\n        for(int i=0; i<n; i++)  {\n            //even index modification \n            if(i%2==0)  {\n                vec2[i] = vec1[i/2];\n                val += abs(vec2[i]-original[i]);\n            }\n            //odd index modification \n            else if(i%2==1) {\n                vec2[i] = vec1[(n/2)+((i-1)/2)];\n                val += abs(vec2[i]-original[i]);\n            }\n        }\n\n        cnt++;\n\n        //case for orginal permutation obtained.\n        if(val==0)  {\n            return;\n        }\n        //case for next permutation modifictaion needed.\n        else {\n            func(original,vec2,vec1,cnt,n);\n        }\n\n    }\n\n    int reinitializePermutation(int n) {\n\n        //declarinh helping vectors & variables\n        vector<int> vec1(n,0);\n        for(int i=0; i<n; i++) vec1[i]=i;\n        vector<int> vec2(n,0);\n        int cnt = 0;\n\n        //recurisve call\n        func(vec1,vec1,vec2,cnt,n);\n\n        return cnt;\n    }\n};\n```\n\n![download (1).jfif](https://assets.leetcode.com/users/images/8ffab349-4136-4f43-8827-3d2257e71240_1677168473.8636894.jpeg)\n\n\n\n
['Array', 'Math', 'Recursion', 'Simulation', 'C++']