recursion + Memoization || Buy/Sell stock intuition
Code\n\nclass Solution {\npublic:\n    int dp[50001][2];\n    int score(vector<int>& v,int i,int f){\n        if(f==-1) return 0;\n        if(i==v.size()) retur
# Code\n```\nclass Solution {\npublic:\n    int dp[50001][2];\n    int score(vector<int>& v,int i,int f){\n        if(f==-1) return 0;\n        if(i==v.size()) return INT_MIN;\n        if(dp[i][f]!=-1) return dp[i][f];\n\n        if(f==0){\n            return dp[i][f]=max(v[i]+i+score(v,i+1,1),score(v,i+1,f));\n        }\n        else{\n            return dp[i][f]=max(v[i]-i+score(v,i+1,-1),score(v,i+1,f));\n        }\n\n    }\n    int maxScoreSightseeingPair(vector<int>& v) {\n        memset(dp,-1,sizeof(dp));\n        return score(v,0,0);\n    }\n};\n```
['Dynamic Programming', 'Memoization', 'C++']