My Solution
\n/**\n * Time Complexity: O(n)\n * Space Complexity: O(n)\n * where `n` is the length of the vector `prizePositions`\n */\nclass Solution {\n public:\n  int ma
```\n/**\n * Time Complexity: O(n)\n * Space Complexity: O(n)\n * where `n` is the length of the vector `prizePositions`\n */\nclass Solution {\n public:\n  int maximizeWin(const vector<int> &prizePositions, const int k) {\n    const int n = static_cast<int>(prizePositions.size());\n    int left[n];\n    for (int max_prices = 0, start = 0, end = 0; end < n; ++end) {\n      while (prizePositions[end] - prizePositions[start] > k) {\n        ++start;\n      }\n      max_prices = max(max_prices, end - start + 1);\n      left[end] = max_prices;\n    }\n    \n    int right[n];\n    for (int max_prices = 0, start = n - 1, end = n - 1; end > -1; --end) {\n      while (prizePositions[start] - prizePositions[end] > k) {\n        --start;\n      }\n      max_prices = max(max_prices, start - end + 1);\n      right[end] = max_prices;\n    }\n    \n    int ret = 0;\n    for (int separator = 0; separator < n; ++separator) {\n      ret = max(ret, left[separator] + (separator + 1 < n ? right[separator + 1] : 0));\n    }\n    return ret;\n  }\n};\n```
[]