dp || sliding window || o(n) || leftmax + rightmax || faster 100%
Intuition\n   For every index i, if we can get leftmax[i-1] and rightmax[i], we can iterate through i and get the max result.\n\nleftmax[i]: max on the left of 
# Intuition\n   For every index i, if we can get leftmax[i-1] and rightmax[i], we can iterate through i and get the max result.\n\nleftmax[i]: max on the left of index i (including i)\nrightmax[i]: max on the right of index i (including i)\n\nTo get leftmax[i]: the max between leftmax[i-1], and the number in the window of size k from i to the left, i.e., i - j + 1, where j is the most left element meeting the window size k requirement for i.\n\nTo get rightmax[i]: the max between rightmax[i+1], and the number in the window of size k from i to the right, i.e., j - i + 1, where j is the most right element meeting the window size k requirement for i.\n\n# Complexity\n- Time complexity: o(n)\n- space complexity : o(n)\n\n\n# Code\n```\nclass Solution {\npublic:\n    int maximizeWin(vector<int>& v, int k) {\n         int n = v.size();\n         vector<int> leftmax(n,1);\n         vector<int> rightmax(n,1);\n         int j=0;\n         for(int i=1;i<n;i++){\n             while(v[i]-v[j]>k)  j++;\n             leftmax[i] = max(leftmax[i-1],i-j+1);\n         }\n        j = n-1;\n         for(int i=n-2;i>=0;i--){\n             while(v[j]-v[i]>k)  j--;\n             rightmax[i] = max(rightmax[i+1],j-i+1);\n         }\n         int ans=0;\n         for(int i=0;i<=n;i++){\n              ans =  max((i==0?0:leftmax[i-1])+(i==n?0:rightmax[i]) , ans);\n         }\n         return ans;\n\n    }\n};\n```
['Sliding Window', 'C++']