C++ O(N) || Sliding Window || DP
Connect with me on LinkedIn: https://www.linkedin.com/in/abhay5349singh/\n\n\nclass Solution {\npublic:\n    int maximizeWin(vector<int>& prizePositions, int k)
**Connect with me on LinkedIn**: https://www.linkedin.com/in/abhay5349singh/\n\n```\nclass Solution {\npublic:\n    int maximizeWin(vector<int>& prizePositions, int k) {\n        int n=prizePositions.size();\n        \n        int i=0, j=0;\n        \n        // maximum no. of prizes which can be selected for segment [0,j] within range k\n        vector<int> l2r(n,0); \n        while(j<n){\n            while(prizePositions[j] - prizePositions[i] > k) i++;\n            \n            if(j>0) l2r[j] = l2r[j-1];\n            l2r[j] = max(l2r[j],j-i+1);\n            \n            j++;\n        }\n        \n        // maximum no. of prizes which can be selected for segment [j,n-1] within range k\n        vector<int> r2l(n,0);\n        i=n-1, j=n-1;\n        while(j>=0){\n            while(prizePositions[i] - prizePositions[j] > k) i--;\n            \n            if(j<n-1) r2l[j] = r2l[j+1];\n            r2l[j] = max(r2l[j],i-j+1);\n            \n            j--;\n        }\n        \n        int ans=1;\n        for(int i=0;i<n-1;i++) ans=max(ans,l2r[i]+r2l[i+1]);\n        \n        return ans;\n    }\n};\n```\n\n**Do upvote if it helps:)**
['Dynamic Programming', 'C++']