DP. Time: O(3*n), Space: O(2*n)
class Solution(object):\n    def maximizeWin(self, prizePositions, k):\n        """\n        :type prizePositions: List[int]\n        :type k: int\n        :rty
class Solution(object):\n    def maximizeWin(self, prizePositions, k):\n        """\n        :type prizePositions: List[int]\n        :type k: int\n        :rtype: int\n        """\n        \n        n = len(prizePositions)\n        \n        jump_arr = [0 for i in range(n)]\n        r = n-1\n        \n        for i in range(n-1,-1,-1):\n            while prizePositions[r] > prizePositions[i] + k:\n                r -= 1\n            \n            jump_arr[i] = r\n        \n        \n        dp_prev = [0 for i in range(n)]\n        \n        max_so_far = 0\n        for i in range(n-1,-1,-1):\n            dp_prev[i] = max(jump_arr[i] - i + 1, max_so_far)\n            max_so_far = dp_prev[i]\n        \n        res = 0\n        for i in range(n-1,-1,-1):\n            cur = jump_arr[i] - i + 1\n            \n            if jump_arr[i] + 1 < n:\n                cur += dp_prev[jump_arr[i] + 1]\n            \n            res = max(res, cur)\n        \n        return res\n\n            \n        \n            \n        \n        \n            \n            \n        \n
[]