✅ Easy Sliding Window with DP + Visual Example ✅
Idea\n- Use sliding window along with 1D dynamic programming. \n- Sliding window will find all possible segments while dp array stores the maximum segment up to
# Idea\n- Use sliding window along with 1D dynamic programming. \n- Sliding window will find all possible segments while `dp` array stores the maximum segment up to each index. \n- Combining these two concepts, sliding window is used for current segment length while `dp` finds a previous maximum segment. \n    - Notice using this method means our segments will never overlap. \n\n##### Sliding Window\n- We increase our window while the segment is *less than or equal to* `k`.\n- Decrease our window when above condition is not satisifed. \n- We want to have a valid window with every iteration so we can check with `dp` for max segments. \n\n##### Dynamic Programming \n- Size $$n+1$$ to initialize `dp[0] = 0` for start max segment size. Conventional and convenient for most DP problems. \n- At each index, we store the maximum segment size up to that point.\n- The candidates for consideration: current segment length `start` to `end` and previous max segment `dp[start]`.\n\n\n# Example\n-  Here is every iteration of case `[1, 1, 2, 2, 3, 3, 5]`\n\n![1.jfif](https://assets.leetcode.com/users/images/77aca49d-2fb7-4b43-a31f-507c94029605_1675882092.2132459.jpeg)\n\n\n\n# Code\n```\nclass Solution {\npublic:\n    int maximizeWin(vector<int>& prizePositions, int k) {\n        int n = prizePositions.size();\n        vector<int> dp(n+1, 0);\n        int res = 0;\n        for (int start = 0, end = 0; end < n; end++){\n            while (prizePositions[end] - prizePositions[start] > k){\n                start++;\n            }\n            dp[end+1] = max(dp[end], end-start+1);\n            res = max(res, end-start+1 + dp[start]);\n        }\n        return res;\n    }\n};\n```\n### Please upvote if this was helpful. Thanks! \n
['C++']