C++ | O(N) | GCD
1. Observation of how gcd(n,k) cases related to array rotation.\nFrom the following observation ,  we know that rorate can seperate into gcd(n,k) cases.\nJust l
# 1. Observation of how gcd(n,k) cases related to array rotation.\nFrom the following observation ,  we know that rorate can seperate into gcd(n,k) cases.\nJust let me say that we can process in different rows. \n```\n    //[0,1,2,3,4,5,6] steps 3\u3000gcd(7,3) = 1\n    //0,3,6,2,5,1,4,\n    \n    //[0,1,2,3,4,5,6,7] steps 4  gcd(8,4)=4\n    //0,4,\n    //1,5,\n    //2,6,\n    //3,7,\n    \n    //[0,1,2,3,4,5,6,7] steps 2  gcd(8,2) = 2\n    //0,2,4,6,\n    //1,3,5,7,\n    \n    //[0,1,2,3,4,5,6,7,8,9,10,11] step 3   gcd(12,3) = 3\n    //0,3,6,9,\n    //1,4,7,10,\n    //2,5,8,11,\n```\n\nFor each row, we can process its rorated move. \nFor example\n```\n    [0,1,2,3,4,5,6,7,8,9,10,11] step 3   gcd(12,3) = 3\n    //0,3,6,9,  -> 9,0,3,6  \\\n    //1,4,7,10  ->10,1 4,7   -=> [9,10,11,0,1,2,3,4,5,6,7,8]\t\n    //2,5,8,11 -> 11,2,5,8  / \n```\n\n# 2. rotate array by two temp variable.\nAnother tool is the way to make rorate move. \nMy idea of rorated move is by using two temp values. \nFor example of rorated move from  A={2,5,8,11} to A={11,2,5,8}. \nI the following explantation, I use notation A\'[0] to mean original A[0]. \nSo whatever A have been changed, It\'s still that A\'[0] =2, A\'[1]=5. A\'[2]=8. A\'[3]=11\nThe following is showing how two temp variable can make help rorated move. \n```  \nprev_temp=NA\ntemp=2\nA is {2,5, 8,11}\n```\n```\nprev_temp=2 //(A\'[0])\ntemp=5  //(A\'[1])\nA[1] = 2 ->  A is {2,2,8,11}\n```\n```\nprev_temp=5 //(A\'[1])\ntemp=8  //(A\'[2])      \nA[2] = 5 ->  A is {2,2,5,11}\n```\n```\nprev_temp=8 //(A\'[2])      \ntemp=11 //(A\'[3])      \nA[3] = 8 ->  A is {2,2,5,8}\n```\n```\nprev_temp=11 //(A\'[3])      \ntemp=2 //(A\'[0])      \nA[0] = 11 ->  A is {11,2,5,8}\n```\n\n\n# 3. outcome of solution\nFrom the observation to seperate row and the idea of rorated move by two temp variable, \nwe can implment the following solution.\n\n```\nclass Solution {\npublic:\n    void rotate(vector<int>& nums, int k) {\n        int n = nums.size();\n        int rows = gcd(n, k);\n        for(int i = 0; i < rows; i++) {\n\t\t\t//seperate into gcd(n,k) rows cases\n            int temp = nums[i];\n            int curr_idx = i;                \n            for(int j = 0 ; j < n / rows; j++) {\n\t\t\t\t//Make a rorated move for each row by two temp\n                int next_idx = (curr_idx + k) % n;\n                int prev_temp = temp;\n                temp = nums[next_idx];\n                nums[next_idx] = prev_temp;\n                curr_idx = next_idx;\n            }\n        }   \n    }\n};\n```\n\n
['C']