Easy C++ O(N) solution  || sliding segment
\nclass Solution {\npublic:\n    int maximizeWin(vector<int>& arr, int k) {\n        //for every index store the result\n        vector<int> dp(arr.size());\n  
```\nclass Solution {\npublic:\n    int maximizeWin(vector<int>& arr, int k) {\n        //for every index store the result\n        vector<int> dp(arr.size());\n        \n        //dp[i] stores the max pos covered by any single segment of length k\n        int res=0;\n        int i=0;\n        int maxiSingle=0;\n        \n        for(int j=0;j<arr.size();j++)\n        {\n            while(arr[i]< arr[j]-k)\n                i++;\n            int dist=j-i+1;\n            maxiSingle=max(maxiSingle,dist);\n            dp[j]=maxiSingle;   \n            //arr[i..j] consits of one segment  and add the max ans for subarray [0..i-1] \n            int curr=dist;\n            if(i>0)\n                curr+=dp[i-1];\n            res=max(res,curr);\n            \n        }\n        return res;\n    }\n};\n```
[]