Java | Two Pointer Solution | Simple & Easy Solution using Left max and Right max
Code\n\nclass Solution {\n    public int maximizeWin(int[] prizePositions, int k) {\n        \n        int n = prizePositions.length;\n        int leftMax[] = n
# Code\n```\nclass Solution {\n    public int maximizeWin(int[] prizePositions, int k) {\n        \n        int n = prizePositions.length;\n        int leftMax[] = new int[n];\n        int rightMax[] = new int[n];\n\n        leftMax[0] = 1;\n        for(int i = 1, j = 0; i < n; i++) {\n            while(prizePositions[i] - prizePositions[j] > k) {\n                j++;\n            }\n            leftMax[i] = Math.max(leftMax[i-1], i-j+1);\n        }\n\n        rightMax[n-1] = 1;\n        for(int i = n-2, j = n-1; i >= 0; i--) {\n            while(prizePositions[j] - prizePositions[i] > k) {\n                j--;\n            }\n            rightMax[i] = Math.max(rightMax[i+1], j-i+1);\n        }\n        \n        int res = 0 ;\n        for(int i = 0; i <= n; i++) {\n            res = Math.max(res, (i == 0 ? 0 : leftMax[i - 1]) + (i == n ? 0 : rightMax[i]));\n        }\n        return res;\n    }\n}\n```\n\n- Do Upvote if this helps \u2B06\uFE0F \uD83D\uDC4D\uD83C\uDFFB \n\n
['Two Pointers', 'Java']