[Python] Maximize Left and Right Segments, The Best
Intuition\nSplit the prizes list such that the number of maximum-count prizes segment of length k in left and right part of the split is maximized.\n\nThe Best!
# Intuition\nSplit the prizes list such that the number of maximum-count prizes segment of length $$k$$ in left and right part of the split is maximized.\n\nThe Best!\n\n# Approach\nUse a sliding window to build two aggregated maximums of $$k$$-length prizes counts when moving from left and from right.\n\nHandle a special case of singleton input array by providing a default value to the final `max()` iterator.\n\n# Complexity\n- Time complexity: $$O(n)$$\n- Space complexity: $$O(n)$$\n\n# Code\n```py\ndef maximizeWin(self, prizes: list[int], k: int) -> int:\n    n, i, j = len(prizes), 0, 0\n    left, right = [0] * n, [0] * n\n\n    while j != n:\n        while prizes[j]-prizes[i] > k:\n            i += 1\n        left[j] = max(j-i+1, left[j-1] if j != 0 else 0)\n        j += 1\n    \n    i = j = n-1\n    while i != -1:\n        while prizes[j]-prizes[i] > k:\n            j -= 1\n        right[i] = max(j-i+1, right[i+1] if i != n-1 else 0)\n        i -= 1\n\n    return max((left[i] + right[i+1] for i in range(n-1)), default=n)\n```
['Python3']