Store longest range in left and right using sliding window
\nclass Solution:\n    def maximizeWin(self, pos, k):\n        n = len(pos)\n        l = [0] * n\n        r = [0] * n\n        i = 0\n        for j in range(n):
```\nclass Solution:\n    def maximizeWin(self, pos, k):\n        n = len(pos)\n        l = [0] * n\n        r = [0] * n\n        i = 0\n        for j in range(n):\n            while i < j and pos[j] - pos[i] > k:\n                i += 1\n            if pos[j] - pos[i] <= k:\n                l[j] = j - i + 1\n        i = n - 1\n        for j in range(n - 1, -1, -1):\n            while i > j and pos[i] - pos[j] > k:\n                i -= 1\n            if pos[i] - pos[j] <= k:\n                r[j] = i - j + 1\n        res = 0\n        maxleft = 0\n        for i in range(n):\n            res = max(res, maxleft + r[i])\n            maxleft = max(maxleft, l[i])\n        return res\n```
[]