[Python] Easy to Understand Binary Search O(M log N)
Idea\n\nConsider every t in the range [2, 2 * limit] as a possible target. What is the cost of making every pair (x, y) sum to t?\n\nWe have to change 0, 1 or 2
**Idea**\n\nConsider every `t` in the range `[2, 2 * limit]` as a possible target. What is the cost of making every pair `(x, y)` sum to `t`?\n\nWe have to change `0`, `1` or `2` numbers in the pair.\nThe minimum we can achieve by changing only `1` number is `min(x, y) + 1`.\nThe maximum we can achieve by changing only `1` number is `max(x, y) + limit`.\n\nTherefore:\n* If `x + y = t`, the cost is `0`.\n* If `min(x, y)  + 1 > t`, the cost is `2` -- we need to decrease both `x` and `y`.\n* If `max(x, y) + limit < t`, the cost is `2` -- we need to increase both `x` and `y`.\n* Otherwise the cost is `1`.\n\nWe can find the number of pairs where (rearranging the inequalities) `min(x, y) >= t` and `max(x, y) < t - limit` using binary search.\n\nComplexity: `O(N log N)`\n\n**Python**\n```python\nclass Solution:\n    def minMoves(self, nums, limit):\n        n = len(nums) // 2\n        pairs = list(zip(nums[:n], list(reversed(nums))[:n]))\n        mins = sorted(map(min, pairs))\n        maxs = sorted(map(max, pairs))\n        sums = collections.Counter(map(sum, pairs))\n        \n        ans = 1e9\n        for t in range(2, 2 * limit + 1):\n            already_equal = sums[t]\n            increase_both = bisect.bisect_left(maxs, t - limit)\n            decrease_both = n - bisect.bisect_left(mins, t)\n            ans = min(ans, n - already_equal + increase_both + decrease_both)\n\n        return ans\n```
[]