JavaScript (DP)
javascript\nvar maximizeWin = function(prizePositions, k) {\n  const dp = {};\n  \n  for (const position of prizePositions)\n    dp[position] = Array(3).fill(0)
```javascript\nvar maximizeWin = function(prizePositions, k) {\n  const dp = {};\n  \n  for (const position of prizePositions)\n    dp[position] = Array(3).fill(0);\n  \n  for (let i = 0, j = 0; i < prizePositions.length; ++i) {\n    const position = prizePositions[i];\n    \n    // range of prizes we can collect is [position - k, position];\n    while (prizePositions[j] < position - k)\n      ++j;\n    \n    for (let interval = 1; interval <= 2; ++interval) {\n      // we have two options:\n\n      // 1) we place the interval so that it ends at `position`\n      //    in doing so we collect i - j + 1 prizes plus \n      //    dp[prizePositions[j - 1]][interval - 1]\n      const maxFromPlacingIntervalAtPosition =\n        i - j + 1 + (j > 0 ? dp[prizePositions[j - 1]][interval - 1] : 0);\n      \n      // 2) we do not place the interval and use the max we got\n      //    at the previous position\n      const maxFromPrevious = i > 0 ? dp[prizePositions[i - 1]][interval] : 0;\n      \n      dp[position][interval] = Math.max(\n        maxFromPlacingIntervalAtPosition, maxFromPrevious\n      );\n    }\n  }\n  \n  return dp[prizePositions[prizePositions.length - 1]][2];\n};\n```
['JavaScript']