Sliding Window +DP O(n)
Intuition\n what if we were allowed to choose only one segment(sliding window)\n what if i save the last  segment with maximum prizes that I can attain from 0<=
# Intuition\n* what if we were allowed to choose only one segment(sliding window)\n* what if i save the last  segment with maximum prizes that I can attain from 0<=j<=i(dynamic programming)\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n* if I am currently at ith position, the maximum prizes I can attain \n**i-start+1** prizes such that **nums[i]-nums[start]<=k** using sliding window.\nNote\n(\n    nums[i]-nums[start]<=k \n    takes care of the condition (The length of each segment must be k)\n    .Even if my length is smaller than k then there is going to be overlapping which is allowed.\n)\n\n* so suppose I can attain **i-start+1** prizes from the ith position , I will try to find the maximum prizes that can be attained in the subarray \nfrom **0<=i< start**(\n which can be calculated by dp\nthat is **dp[i]=max(i-start+1,dp[i-1])**;\n\n).\n# Complexity\n- Time complexity: amortised O(n)\n- Space complexity: O(n) (size of array dp)\n# Code\n```\nclass Solution\n{\npublic:\n    int maximizeWin(vector<int> &nums, int k)\n    {\n        int n = nums.size(), start = 0, ans = 0;\n        vector<int> dp(n);\n        for (int i = 0; i < n; i++)\n        {\n            while (nums[i] - nums[start] > k)\n                    start++;\n            \n            ans = max(ans, i - start + 1 + (start > 0 ? dp[start - 1] : 0));\n            dp[i] = max((i > 0 ? dp[i - 1] : 0), i - start + 1);\n        }\n        return ans;\n    }\n};\n```
['Dynamic Programming', 'Sliding Window', 'C++']