Memoization -> Tabulation | DP + BS | C++
Memoization\n\nclass Solution {\n    int dfs(int i, int n, int k, int cnt, vector<int> &pp, vector<vector<int>> &dp) {\n        if(i == n) return 0;\n        if
# Memoization\n```\nclass Solution {\n    int dfs(int i, int n, int k, int cnt, vector<int> &pp, vector<vector<int>> &dp) {\n        if(i == n) return 0;\n        if(dp[i][cnt] != -1) return dp[i][cnt];\n\n        int notPick = dfs(i + 1, n, k, cnt, pp, dp), pick = 0;\n        if(cnt) {\n            int pos = lower_bound(pp.begin() + i, pp.end(), pp[i] + k + 1) - pp.begin() - 1;\n            pick = pos - i + 1 + dfs(pos + 1, n, k, cnt - 1, pp, dp);\n        }\n        return dp[i][cnt] = max(pick, notPick);\n    }\npublic:\n    int maximizeWin(vector<int>& pp, int k) {\n        int n = pp.size();\n        vector<vector<int>> dp(n, vector<int>(3, -1));\n\n        return dfs(0, n, k, 2, pp, dp);\n    }\n};\n```\n\n# Tabulation\n```\nclass Solution {\npublic:\n    int maximizeWin(vector<int>& pp, int k) {\n        int n = pp.size();\n        vector<vector<int>> dp(n + 1, vector<int>(3));\n\n        for(int i=n-1; i>=0; i--) {\n            for(int cnt=1; cnt<=2; cnt++) {\n                int notPick = dp[i + 1][cnt], pick = 0;\n                int pos = lower_bound(pp.begin() + i, pp.end(), pp[i] + k + 1) - pp.begin() - 1;\n                pick = pos - i + 1 + dp[pos + 1][cnt - 1];\n                dp[i][cnt] = max(pick, notPick);\n            }\n        }\n        return dp[0][2];\n    }\n};\n```
['Binary Search', 'Dynamic Programming', 'Memoization', 'C++']