C++ | easy to understand
\tclass Solution {\n\tpublic:\n\t\tint minMoves(vector& nums, int limit) {\n\t\t\tint n = nums.size();\n\t\t\tint statechangeArr[ 2*limit + 2 ];\n\t\t\tmemset(s
\tclass Solution {\n\tpublic:\n\t\tint minMoves(vector<int>& nums, int limit) {\n\t\t\tint n = nums.size();\n\t\t\tint statechangeArr[ 2*limit + 2 ];\n\t\t\tmemset(statechangeArr,0,sizeof(statechangeArr));\n\t\t\tint ans = INT_MAX;\n\t\t\tfor(int i = 0 ;i < n/2; i++){\n\t\t\t\tstatechangeArr[0]+=2;\n\t\t\t\tint cur_sum = nums[i] + nums[n - i - 1];\n\n\n\t\t\t\tstatechangeArr[ cur_sum ] -= 1;\n\t\t\t\tstatechangeArr[ cur_sum + 1 ] += 1;\n\t\t\t\tstatechangeArr[ max( nums[i] + limit, nums[n - i - 1] + limit ) + 1 ] += 1;\n\t\t\t\tstatechangeArr[ min( nums[i] + 1, nums[n - i - 1] + 1 ) ] -= 1;\n\t\t\t}\n\t\t\tint cur_num = 0;\n\t\t\tfor(int state: statechangeArr){\n\t\t\t\tcur_num += state;\n\t\t\t\tans = min(ans,cur_num);\n\t\t\t}\n\t\t\treturn ans;\n\t\t}\n\t};
[]