Java | swipe line O(n) with picture to explain very easy to understand
Intuition\n Describe your first thoughts on how to solve this problem. \nbased on the constraint: nums[i] <= limit, we can derive the following intervals with n
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nbased on the constraint: nums[i] <= limit, we can derive the following intervals with number of changes that they need: \n// 1. [a + b, a + b] , 0 step \n// 2. [a + 1, a + limit] , 1\n// 3. [b + 1, b + limit], 1\n// 4. [2, limit + limit], 2\nbecause we have the constaint: nums[i] <= limit, we can plot those intervals into x coordinate:\n     +2........          -1   .............         ......-1.  ...+1 ................          + 1                                     ...........+1  ...................-2    \n2  ..min(a + 1, b + 1) .. (a + b)  .. max(a + limit, b + limit) ..      (limit + limit)\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)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    public int minMoves(int[] nums, int limit) {\n        int[] steps = new int[2 * limit + 2];\n        int result = Integer.MAX_VALUE;\n        for (int index = 0; index < nums.length / 2; index++) {\n            int first = nums[index];\n            int second = nums[nums.length - 1 - index];\n            steps[2] += 2;\n            steps[Math.min(first + 1, second + 1)] -= 1;\n            steps[first + second] -= 1;\n            steps[first + second + 1] += 1;\n            steps[Math.max(first + limit, second + limit) + 1] += 1;\n            steps[limit + limit + 1] -= 2;\n        }\n\n        int sum = 0;\n        for (int index = 2; index <= limit + limit; index++) {\n            sum += steps[index];\n            result = Math.min(result, sum );\n        }\n        return result;\n    }\n}\n```
['Java']