Prefix+Suffix+BS using python
Code\n\nclass Solution:\n    def maximizeWin(self, pp: List[int], k: int) -> int:\n        n=len(pp)\n        \n        pre=[0]*(n)\n        suff=[0]*(n)\n     
# Code\n```\nclass Solution:\n    def maximizeWin(self, pp: List[int], k: int) -> int:\n        n=len(pp)\n        \n        pre=[0]*(n)\n        suff=[0]*(n)\n        \n        for i in range(n-1,-1,-1):\n            pos=bisect_right(pp,pp[i]+k)\n            if i==n-1:\n                suff[i]=pos-i\n            else:\n                suff[i]=max(pos-i,suff[i+1])\n                \n            pos=bisect_right(pp,pp[i]-k-1)\n            pre[i]=i-pos+1\n            \n        for i in range(1,n):\n            pre[i]=max(pre[i-1],pre[i])\n        \n        ans=pre[0]\n        # for i in range(n-2,-1,-1):\n        #     suff[i]=max(suff[i+1],suff[i])\n        for i in range(n-1):\n            ans=max(ans,pre[i]+suff[i+1])\n            \n        return ans\n```
['Python3']