leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

commit dbd844520d27f75c1d401462217499f2961467a8
parent 4fafc96a132fb3b9605f3078b119b91e2884b7fa
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Fri, 12 May 2023 14:18:46 +0200

Daily Problem

Diffstat:
AProblems/2140.cpp | 15+++++++++++++++
MREADME.md | 1+
2 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/Problems/2140.cpp b/Problems/2140.cpp @@ -0,0 +1,15 @@ +class Solution { + static const int size = 1E5 + 1; + long long dp[size]; + +public: + Solution() { memset(dp, 0xFF, sizeof(dp)); } + + long long mostPoints(const vector<vector<int>> &questions, int i = 0) { + if (i >= questions.size()) return 0; + if (dp[i] != -1) return dp[i]; + return dp[i] = max(questions[i][0] + + mostPoints(questions, i + questions[i][1] + 1), + mostPoints(questions, i + 1)); + } +}; diff --git a/README.md b/README.md @@ -499,6 +499,7 @@ for solving problems. | 2115 | Medium | [Find All Possible Recipes from Given Supplies](Problems/2115.cpp) | | 2130 | Medium | [Maximum Twin Sum of a Linked List](Problems/2130.cpp) | | 2131 | Medium | [Longest Palindrome by Concatenating Two Letter Words](Problems/2131.cpp) | +| 2140 | Medium | [Solving Questions With Brainpower](Problems/2140.cpp) | | 2177 | Medium | [Find Three Consecutive Integers That Sum to a Given Number](Problems/2177.cpp) | | 2181 | Medium | [Merge Nodes in Between Zeros](Problems/2181.cpp) | | 2187 | Medium | [Minimum Time to Complete Trips](Problems/2187.cpp) |