Slide Window
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```csharp []
public class Solution {
    public int MaximizeWin(int[] prizePositions, int k) {
        // Pre cal num frequency:
        SortedDictionary<int, int> freq = new();
        foreach(int n in prizePositions)
        {
            freq.TryAdd(n, 0);
            freq[n]++;
        }

        List<int> keys = freq.Keys.ToList();
        int kLen = keys.Count, sum = 0, start = 0, end = kLen-1;
        int[] preSum = new int[kLen], tailSum = new int[kLen];

        for(int i = 0; i < kLen; i++)
        {
            sum += freq[keys[i]];
            while(keys[i]-keys[start] > k)
            {
                sum -= freq[keys[start++]];
            }

            preSum[i] = Math.Max(i > 0 ? preSum[i-1] : 0, sum);
        }

        sum = 0;
        for(int i = kLen-1; i >= 0; i--)
        {
            sum += freq[keys[i]];
            while(keys[end] - keys[i] > k)
            {
                sum -= freq[keys[end--]];
            }

            tailSum[i] = Math.Max(i < kLen-1 ? tailSum[i+1] : 0, sum);
        }

        int maxSum = 0;
        for(int i = 0; i < kLen; i++)
        {
            int curSum = (i > 0 ? preSum[i-1] : 0) + tailSum[i];
            maxSum = Math.Max(curSum, maxSum);
        }

        return maxSum;
    }
}
```
['C#']