question_slug
stringlengths
3
77
title
stringlengths
1
183
slug
stringlengths
12
45
summary
stringlengths
1
160
author
stringlengths
2
30
certification
stringclasses
2 values
created_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
updated_at
stringdate
2013-10-25 17:32:12
2025-04-12 09:38:24
hit_count
int64
0
10.6M
has_video
bool
2 classes
content
stringlengths
4
576k
upvotes
int64
0
11.5k
downvotes
int64
0
358
tags
stringlengths
2
193
comments
int64
0
2.56k
maximum-containers-on-a-ship
Easiest solution
easiest-solution-by-prajapatiabhishek150-59lb
Complexity Time complexity: Code
PrajapatiAbhishek1504
NORMAL
2025-03-28T20:56:16.086303+00:00
2025-03-28T20:56:16.086303+00:00
2
false
# Complexity - Time complexity: ![image.png](https://assets.leetcode.com/users/images/5a1c6539-ed95-4896-b081-1ab0a6e37732_1743195316.5661032.png) # Code ```java [] class Solution { public int maxContainers(int n, int w, int maxWeight) { return Math.min(n*n,maxWeight/w); } } ```
0
0
['Math', 'C++', 'Java', 'Python3']
0
maximum-containers-on-a-ship
Easiest Solution using Math
easiest-solution-using-math-by-prajapati-wgtg
IntuitionApproachComplexity Time complexity: Space complexity: Code
PrajapatiAbhishek1504
NORMAL
2025-03-28T20:54:03.570635+00:00
2025-03-28T20:54:03.570635+00:00
1
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: ![image.png](https://assets.leetcode.com/users/images/12d6e0ae-b29b-423e-976f-d972081014b0_1743195228.6891682.png) - Space complexity: <!...
0
0
['Math', 'Java']
0
maximum-containers-on-a-ship
Very Easy Understandable Solution || JAVA
very-easy-understandable-solution-java-b-btp2
Code
sumo25
NORMAL
2025-03-28T17:37:13.929025+00:00
2025-03-28T17:37:13.929025+00:00
2
false
# Code ```java [] class Solution { public int maxContainers(int n, int w, int maxWeight) { int cell=n*n; int count=0; while(count+1<=cell && maxWeight-w>=0){ count++; maxWeight-=w; } return count; } } ```
0
0
['Java']
0
maximum-containers-on-a-ship
Simple solution -> Beats 100.00%
simple-solution-beats-10000-by-developer-yx7m
IntuitionApproachComplexity Time complexity: O(1) Space complexity: O(1) Code
DevelopersUsername
NORMAL
2025-03-28T17:08:22.013212+00:00
2025-03-28T17:08:22.013212+00:00
1
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: O(1) - Space complexity: O(1) # Code ```java [] class Solution { public int maxContainers(int n, int w, int maxWeight) { retu...
0
0
['Java']
0
maximum-containers-on-a-ship
C
c-by-n97rvh-z9fw
Code
N97RVH
NORMAL
2025-03-28T16:13:48.762212+00:00
2025-03-28T16:13:48.762212+00:00
5
false
# Code ```c [] int maxContainers(int n, int w, int maxWeight) { int ans = maxWeight / w; return (ans > (n * n) ? n * n: ans); } ```
0
0
['C']
0
maximum-containers-on-a-ship
[Python] min(maxWeight // w, n*n)
python-minmaxweight-w-nn-by-pbelskiy-5d7b
null
pbelskiy
NORMAL
2025-03-28T14:16:05.536732+00:00
2025-03-28T14:16:05.536732+00:00
1
false
```python3 [] class Solution: def maxContainers(self, n: int, w: int, maxWeight: int) -> int: return min(maxWeight // w, n*n) ```
0
0
['Python3']
0
maximum-containers-on-a-ship
single line output
single-line-output-by-vijayakumar-1728-c33n
Code
vijayakumar-1728
NORMAL
2025-03-28T04:53:08.481172+00:00
2025-03-28T04:53:08.481172+00:00
1
false
# Code ```java [] class Solution { public int maxContainers(int n, int w, int maxWeight) { return Math.min(n*n,maxWeight/w); } } ```
0
0
['Java']
0
maximum-containers-on-a-ship
Python3 O(1) Approach
kotlin-o1-approach-by-curenosm-b7mz
Code
curenosm
NORMAL
2025-03-28T00:25:02.862420+00:00
2025-03-28T00:25:14.026429+00:00
3
false
# Code ```python3 [] class Solution: def maxContainers(self, n: int, w: int, maxWeight: int) -> int: return min(n * n, maxWeight // w) ```
0
0
['Python3']
0
maximum-containers-on-a-ship
One Line Solution
one-line-solution-by-s_piyushhh-b19h
Complexity Time complexity: O[1] Space complexity: O[1] Code
s_piyushhh
NORMAL
2025-03-27T18:55:14.287536+00:00
2025-03-27T18:55:14.287536+00:00
1
false
# Complexity - Time complexity: O[1] <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: O[1] # Code ```cpp [] class Solution { public: int maxContainers(int n, int w, int maxWeight) { return min(n*n, maxWeight/w); } }; ``` ```python [] class Solution(object): def maxContaine...
0
0
['C++']
0
maximum-containers-on-a-ship
beginner level easy c solution 0 ms 100% beats
beginner-level-easy-c-solution-0-ms-100-bbaw0
IntuitionApproachComplexity Time complexity: Space complexity: Code
kunsh2301
NORMAL
2025-03-27T18:03:43.684598+00:00
2025-03-27T18:03:43.684598+00:00
5
false
# Intuition <!-- Describe your first thoughts on how to solve this problem. --> # Approach <!-- Describe your approach to solving the problem. --> # Complexity - Time complexity: <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code `...
0
0
['C']
0
maximum-containers-on-a-ship
C++ one-liner, beats 100%
c-one-liner-beats-100-by-akshar-jhxu
Code
akshar_
NORMAL
2025-03-27T16:32:27.179404+00:00
2025-03-27T16:32:27.179404+00:00
1
false
# Code ```cpp [] class Solution { public: int maxContainers(int n, int w, int maxWeight) { return min(n * n, maxWeight / w); } }; ```
0
0
['Math', 'C++']
0
maximum-containers-on-a-ship
Most easiest question ever solved. Best for beginners
most-easiest-question-ever-solved-best-f-8cp7
IntuitionIt is quite difficult but after clearly understanding the question.it just few seconds to solve this oneApproachMathematical ApproachComplexity Time co
PradeepSS25
NORMAL
2025-03-27T15:21:16.313629+00:00
2025-03-27T15:21:16.313629+00:00
1
false
# Intuition It is quite difficult but after clearly understanding the question.it just few seconds to solve this one # Approach Mathematical Approach # Complexity - Time complexity: O(1) - Space complexity: O(1) # Code ```python [] class Solution(object): def maxContainers(self, n, w, maxWeight): return min(...
0
0
['Python']
0
maximum-containers-on-a-ship
Go
go-by-marcdidom-rkj0
Code
marcdidom
NORMAL
2025-03-27T14:43:47.307996+00:00
2025-03-27T14:43:47.307996+00:00
3
false
# Code ```golang [] func maxContainers(n, w, maxWeight int) int { totalCells := n * n possibleByWeight := maxWeight / w if totalCells < possibleByWeight { return totalCells } return possibleByWeight } ```
0
0
['Go']
0
maximum-containers-on-a-ship
Beats 100%, 1 LOC
beats-100-1-loc-by-nisargshahh-kvl2
Code
nisargshahh
NORMAL
2025-03-27T13:12:31.044149+00:00
2025-03-27T13:12:31.044149+00:00
1
false
# Code ```cpp [] class Solution { public: int maxContainers(int n, int w, int maxWeight) { return min(n*n, maxWeight / w); } }; ```
0
0
['C++']
0
maximum-containers-on-a-ship
[C++] Simple Check
c-simple-check-by-lokeshpaidi-c3mq
Intuition / Approach Simple Check Complexity Time complexity: O(1) Space complexity: O(1) Code
LokeshPaidi
NORMAL
2025-03-27T07:03:46.983521+00:00
2025-03-27T07:03:46.983521+00:00
1
false
# Intuition / Approach - Simple Check # Complexity - Time complexity: O(1) <!-- Add your time complexity here, e.g. $$O(n)$$ --> - Space complexity: O(1) <!-- Add your space complexity here, e.g. $$O(n)$$ --> # Code ```cpp [] class Solution { public: int maxContainers(int n, int w, int maxWeight) { if(n*...
0
0
['C++']
0
maximum-containers-on-a-ship
python
python-by-alex72112-cx3o
Code
alex72112
NORMAL
2025-03-27T05:42:15.714952+00:00
2025-03-27T05:42:15.714952+00:00
3
false
# Code ```python3 [] class Solution: def maxContainers(self, n: int, w: int, maxWeight: int) -> int: return int(min(n * n, maxWeight / w)) ```
0
0
['Python3']
0
maximum-containers-on-a-ship
1 liner | Beats 100% |
1-liner-beats-100-by-shoryasethia-j2b9
Approach(n*n*w<=maxWeight) is true then n*n else maxWeight/w.Complexity Time complexity: O(1) Space complexity: None Code
shoryasethia
NORMAL
2025-03-26T22:02:35.943295+00:00
2025-03-26T22:02:35.943295+00:00
2
false
# Approach `(n*n*w<=maxWeight)` is true then `n*n` else `maxWeight/w`. # Complexity - Time complexity: O(1) - Space complexity: None # Code ```cpp [] class Solution { public: int maxContainers(int n, int w, int maxWeight) { return (n*n*w<=maxWeight) ? n*n:maxWeight/w; } }; ```
0
0
['C++']
0
maximum-containers-on-a-ship
one liner super easy
one-liner-super-easy-by-antarab-gfw1
Intuitionmax of contanier present and container that can holdApproachn*n = max container presentComplexity Time complexity:
antarab
NORMAL
2025-03-26T20:31:04.672910+00:00
2025-03-26T20:31:04.672910+00:00
2
false
# Intuition max of contanier present and container that can hold # Approach n*n = max container present # Complexity - Time complexity: $$O(1) - Space complexity: O(1) # Code ```python3 [] class Solution: def maxContainers(self, n: int, w: int, maxWeight: int) -> int: ans1= maxWeight //w return ...
0
0
['Python3']
0
stone-game-vii
C++/Python O(n * n)
cpython-on-n-by-votrubac-0l5y
Sounds like a search problem. Try a stone from each side, and recursively calculate the difference. Maximize the difference among two choices to play optimally.
votrubac
NORMAL
2020-12-13T04:01:20.830837+00:00
2020-12-14T01:10:44.901437+00:00
12,431
false
Sounds like a search problem. Try a stone from each side, and recursively calculate the difference. Maximize the difference among two choices to play optimally. \n\nWe can memoise the results for the start (`i`) and end(`j`) of the remaining stones.\n\n**C++**\n```cpp\nint dp[1001][1001] = {};\nint dfs(vector<int>& s, ...
136
6
[]
18
stone-game-vii
[C++/Java/Python] Minimax, Top down, Bottom up DP - Clean & Concise
cjavapython-minimax-top-down-bottom-up-d-pqb3
Approach 1: Minimax Algorithm\nIdea\n- Let\'s Alice be a maxPlayer and Bob be a minPlayer. On each turn, we need to maximize score of the maxPlayer and minimize
hiepit
NORMAL
2020-12-13T04:02:03.390492+00:00
2021-06-11T18:46:41.821075+00:00
9,082
false
**Approach 1: Minimax Algorithm**\n**Idea**\n- Let\'s `Alice` be a `maxPlayer` and `Bob` be a `minPlayer`. On each turn, we need to maximize score of the `maxPlayer` and minimize score of the `minPlayer`. After all, the final score is the difference in Alice and Bob\'s score if they both play optimally.\n- More about d...
115
5
[]
19
stone-game-vii
JS, Python, Java, C++ | Easy DP Solution w/ Explanation
js-python-java-c-easy-dp-solution-w-expl-oimp
(Note: This is part of a series of Leetcode solution explanations. If you like this solution or find it useful, please upvote this post.)\n\n---\n\n#### Idea:\n
sgallivan
NORMAL
2021-06-11T08:05:03.344628+00:00
2021-06-14T19:21:58.123150+00:00
5,074
false
*(Note: This is part of a series of Leetcode solution explanations. If you like this solution or find it useful,* ***please upvote*** *this post.)*\n\n---\n\n#### ***Idea:***\n\nLike most of the Stone Game problems, this one boils down to a system of ever-repeating subproblems, as the there are many different ways to g...
83
6
['C', 'Python', 'Java', 'JavaScript']
0
stone-game-vii
C++ Bottom-up DP O(N^2) time
c-bottom-up-dp-on2-time-by-lzl124631x-jsyw
\nSee my latest update in repo LeetCode\n\n## Solution 1. Bottom-up DP\n\nLet dp[i][j] be the maximum difference the first player can get if the players play on
lzl124631x
NORMAL
2020-12-13T04:01:06.312247+00:00
2021-01-19T05:56:18.248276+00:00
5,484
false
\nSee my latest update in repo [LeetCode](https://github.com/lzl124631x/LeetCode)\n\n## Solution 1. Bottom-up DP\n\nLet `dp[i][j]` be the maximum difference the first player can get if the players play on `A[i..j]`.\n\n```\ndp[i][j] = max(\n sum(i + 1, j) - dp[i + 1][j], // if the first player choose `...
72
3
[]
14
stone-game-vii
C++ memoization code with proper explanation
c-memoization-code-with-proper-explanati-m24q
\n\nclass Solution {\npublic:\n int dp[1001][1001];\n int solve(vector<int>& stones, int i, int j, int sum){\n if(i>=j){\n return 0;\n
roger2001
NORMAL
2021-06-03T10:01:00.578298+00:00
2021-08-16T08:21:22.263856+00:00
3,512
false
\n```\nclass Solution {\npublic:\n int dp[1001][1001];\n int solve(vector<int>& stones, int i, int j, int sum){\n if(i>=j){\n return 0;\n }\n if(sum<=0){\n return 0;\n }\n if(dp[i][j]!=-1){\n return dp[i][j];\n }\n \n // both...
51
1
['Memoization', 'C', 'C++']
3
stone-game-vii
[Python] O(n*n) dp solution, how to avoid TLE, explained
python-onn-dp-solution-how-to-avoid-tle-d2lz9
We can see dynamic programming structure in this problem: each time we take some stones from the left or from the left side, what is rest is always contigious a
dbabichev
NORMAL
2021-06-11T08:24:48.686919+00:00
2021-06-11T08:24:48.686968+00:00
2,135
false
We can see dynamic programming structure in this problem: each time we take some stones from the left or from the left side, what is rest is always contigious array. So, let us denote by `dp(i, j)` the biggest difference in scores for the person who start with this position.\n\n1. If `i > j`, then we have empty array a...
44
1
['Dynamic Programming']
3
stone-game-vii
Stone Game VII | JS, Python, Java, C++ | Easy DP Solution w/ Explanation
stone-game-vii-js-python-java-c-easy-dp-zcq1w
(Note: This is part of a series of Leetcode solution explanations. If you like this solution or find it useful, please upvote this post.)\n\n---\n\n#### Idea:\n
sgallivan
NORMAL
2021-06-11T08:05:36.898260+00:00
2021-06-14T19:22:26.858569+00:00
1,923
false
*(Note: This is part of a series of Leetcode solution explanations. If you like this solution or find it useful,* ***please upvote*** *this post.)*\n\n---\n\n#### ***Idea:***\n\nLike most of the Stone Game problems, this one boils down to a system of ever-repeating subproblems, as the there are many different ways to g...
44
1
[]
4
stone-game-vii
[Python] Top Down and Bottom Up DP - explained
python-top-down-and-bottom-up-dp-explain-71z4
Approach:\n\nEach player is trying to maximize their score so\nwhen Alice picks up a stone[i] she gains the \nremaining points in the array knowing that Bob\nwi
rowe1227
NORMAL
2020-12-13T04:12:50.360777+00:00
2020-12-13T18:17:12.252597+00:00
2,607
false
**Approach:**\n\nEach player is trying to maximize their score so\nwhen Alice picks up a stone[i] she gains the \nremaining points in the array knowing that Bob\nwill pick the optimal stone next round.\n\nRather than giving Bob the points, we subtract\nBob\'s points from Alice\'s points.\n\n***think of it like Bob gets...
34
2
[]
9
stone-game-vii
Unfriendly to python, why my python O(n^2) topdown dp got MLE;
unfriendly-to-python-why-my-python-on2-t-rxr6
conclusion\n\ndiff\nclass Solution:\n def stoneGameVII(self,A) -> int:\n n = len(A)\n @lru_cache(None)\n def dp(i,j):\n if j-
migeater
NORMAL
2020-12-13T04:04:04.439028+00:00
2022-02-14T08:35:30.433159+00:00
1,692
false
## conclusion\n\n```diff\nclass Solution:\n def stoneGameVII(self,A) -> int:\n n = len(A)\n @lru_cache(None)\n def dp(i,j):\n if j-i+1<=0: return 0\n if (j-i+1) %2 == n%2: return max(dp(i+1,j),dp(i,j-1))\n return min(A[i]+dp(i+1,j),A[j]+dp(i,j-1))\n- return...
29
3
[]
8
stone-game-vii
[Java] DP with a bit of explanation, O(n^2) time, O(n) space
java-dp-with-a-bit-of-explanation-on2-ti-10sa
First a bit of analysis:\n\n\n\n\n\nFrom the table we can find the state transfer function:\n\nresult(stones[0 .. n]) = max(\n\tsum(stones[1 .. n]) - result(sto
joor
NORMAL
2020-12-13T04:06:55.045829+00:00
2020-12-13T10:55:52.963418+00:00
1,595
false
First a bit of analysis:\n\n![image](https://assets.leetcode.com/users/images/ad65926b-0d16-4c1a-891f-ce6fe171519d_1607832274.9623156.png)\n\n\n\nFrom the table we can find the state transfer function:\n```\nresult(stones[0 .. n]) = max(\n\tsum(stones[1 .. n]) - result(stones[1 .. n]),\n\tsum(stones[0 .. n - 1]) - resu...
28
0
[]
5
stone-game-vii
JAVA - Journey from Brute Force to Most Optimized DP (✅)
java-journey-from-brute-force-to-most-op-wbi6
Let\'s try to understand the problem first. \nI think that one statement of Bob always losing and trying to get minimum score difference might lead to confusion
techtutelage
NORMAL
2021-06-11T18:10:36.142743+00:00
2021-06-11T18:12:41.585474+00:00
1,197
false
Let\'s try to understand the problem first. \nI think that one statement of Bob always losing and trying to get minimum score difference might lead to confusion. But it is simple what it meant is that Bob wants to mininum his loss score i.e. `minimize(Alice\'s Winnings - Bob\'s Winnings)` while Alice wants this to maxi...
14
0
['Dynamic Programming', 'Java']
3
stone-game-vii
Python: Explained DP both Memoization(Top-Down) and Tabulation(Bottom-Up)
python-explained-dp-both-memoizationtop-f65zy
This problem cannot be solved using Greedy Approach as both Alice and Bob needs to play optimally and greedy always does not guarantee an optimal solution.\n\nS
meaditya70
NORMAL
2021-06-11T18:40:06.757842+00:00
2021-06-11T18:46:41.725893+00:00
1,053
false
This problem cannot be solved using Greedy Approach as both Alice and Bob needs to play optimally and greedy always does not guarantee an optimal solution.\n\nSo, the only possible way to solve this is to enumerate all the possibilities Alice/Bob has in each turn. \nE.g.: stones = [5,3,1,4,2]\nAlice chooses both 5 and ...
13
1
['Dynamic Programming', 'Memoization', 'Python']
1
stone-game-vii
✅ Stone Game VII | Dynamic Programming | Explanation
stone-game-vii-dynamic-programming-expla-gsdu
Intuition:\n\n1. Both Alice and Bob is playing optimally, so we need to consider the situation for one person.\n2. Let us say we are considering Alice case, if
shivaye
NORMAL
2021-06-11T07:38:35.559606+00:00
2021-06-11T08:01:48.650296+00:00
989
false
**Intuition:**\n```\n1. Both Alice and Bob is playing optimally, so we need to consider the situation for one person.\n2. Let us say we are considering Alice case, if Alice starts first then she has two options:\n* She can remove the first stone in the current stones.\n* She can remove the last stone in the current sto...
13
2
['C']
1
stone-game-vii
🎨 The ART of Dynamic Programming
the-art-of-dynamic-programming-by-clayto-wovf
\uD83C\uDFA8 The ART of Dynamic Programming\n\n1. All possibilities are considered via top-down brute-force depth-first-search\n2. Remember each subproblem\'s o
claytonjwong
NORMAL
2021-06-11T15:05:17.702028+00:00
2021-06-11T15:11:57.914706+00:00
858
false
[\uD83C\uDFA8 The ART of Dynamic Programming](https://leetcode.com/discuss/general-discussion/712010/The-ART-of-Dynamic-Programming-An-Intuitive-Approach%3A-from-Apprentice-to-Master)\n\n1. **A**ll possibilities are considered via top-down brute-force depth-first-search\n2. **R**emember each subproblem\'s optimal solut...
11
3
[]
0
stone-game-vii
[Python3] Easy code with explanation - DP
python3-easy-code-with-explanation-dp-by-wqny
The subproblem for the DP solution is that,\nFor n = 1, Alice or Bob picks the stone and nobody gets any score.\nFor n = 2, the person picks first stone and the
mihirrane
NORMAL
2020-12-14T07:36:50.828904+00:00
2020-12-16T00:46:54.974428+00:00
1,500
false
The subproblem for the DP solution is that,\nFor n = 1, Alice or Bob picks the stone and nobody gets any score.\nFor n = 2, the person picks first stone and the score equals second stone or vice versa.\nso on....\n\nNow, that we have the subproblem how do we fill the DP table and fill it with what?\nI thought of 3 choi...
9
0
['Dynamic Programming', 'Memoization', 'Python', 'Python3']
0
stone-game-vii
C++| 100% | Detailed Explanation | DP Approach
c-100-detailed-explanation-dp-approach-b-gh07
This is similar to Matrix Chain Multiplication Problem . The idea is to divide problem into subproblems and use them to constuct final solution using Dynamic Pr
prajwalroxman
NORMAL
2020-12-15T12:54:06.586057+00:00
2020-12-15T14:46:37.743426+00:00
764
false
This is similar to Matrix Chain Multiplication Problem . The idea is to divide problem into subproblems and use them to constuct final solution using Dynamic Programming .\n\nFor instance given input `[5,3,1,4,2]`\nUse the following `N x N` matrix to compute the result where `N is length of stones[]`\n```\n\t0 , 1 , ...
8
0
[]
0
stone-game-vii
2-Solutions Recursive and Top-Down DP
2-solutions-recursive-and-top-down-dp-by-auqp
Intuition\nMaximization of the choices we pick and constraints were 1000 so N^2 could work\n\n# Approach\nWe have two choiches at a point :\n- Whether pick from
upadhyayabhi0107
NORMAL
2022-11-18T18:25:22.047518+00:00
2022-11-18T18:25:22.047552+00:00
995
false
# Intuition\nMaximization of the choices we pick and constraints were 1000 so N^2 could work\n\n# Approach\nWe have two choiches at a point :\n- Whether pick from the start\n- Or pick from the end \n\nAnd for maintaining the profit sum we could directly subtract it from the sum that we make the call for the rest.\n\n# ...
7
0
['Dynamic Programming', 'Recursion', 'C++']
1
stone-game-vii
Detailed explanation, simple memoization using Java
detailed-explanation-simple-memoization-w4lo3
Just think like a child. At every step there are 2 possibilities, \n\t1 .Picking the first stone.\n\t2. Picking the last stone.\n\nAt each step both of them wan
prakhar3agrwal
NORMAL
2021-06-11T08:26:35.504440+00:00
2021-06-11T08:28:06.135917+00:00
358
false
Just think like a child. At every step there are 2 possibilities, \n\t1 .Picking the first stone.\n\t2. Picking the last stone.\n\nAt each step both of them want to maximize the difference between their current score and the score that the other playes gets in the next step. This will be achieved by "maximizing the dif...
7
1
[]
2
stone-game-vii
C++ DP MinMAX solution. N^2
c-dp-minmax-solution-n2-by-chejianchao-f31v
dp[i][j] represent tha maximum different between i to j. and here we use val - dfs() to calculate different, this is a general way to calculate a MinMax value a
chejianchao
NORMAL
2020-12-13T04:03:03.789595+00:00
2020-12-13T04:19:26.091618+00:00
731
false
dp[i][j] represent tha maximum different between i to j. and here we use val - dfs() to calculate different, this is a general way to calculate a MinMax value and we don\'t need to consider whose turn now.\n```\nclass Solution {\npublic:\n int dp[1001][1001];\n int dfs(vector<int>& stones, int left, int right) {\...
7
0
[]
0
stone-game-vii
Easy to understand | dp solution | O(n^2) |CPP
easy-to-understand-dp-solution-on2-cpp-b-2mbm
let me firstly explain the logic involved:\nbasically we have to find the minimum difference bw Alice and Bobs overall score.\n\nlet us consider the scenario fo
suriansh
NORMAL
2021-05-11T10:00:29.431765+00:00
2021-05-13T06:46:45.292422+00:00
589
false
let me firstly explain the logic involved:\nbasically we have to find the minimum difference bw Alice and Bobs overall score.\n\nlet us consider the scenario for one move of alice:\nShe will have and array of stones from 0....n indices let it be A.Now she has 2 options:\n1) She takes the first element .Impact on her sc...
6
0
['Dynamic Programming', 'C++']
0
stone-game-vii
[Python3] Game Theory + Dynamic Programming - Simple Solution
python3-game-theory-dynamic-programming-v7tqz
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time
dolong2110
NORMAL
2024-09-09T17:51:39.241471+00:00
2024-09-12T08:23:51.880698+00:00
152
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ --...
5
0
['Array', 'Math', 'Dynamic Programming', 'Game Theory', 'Python3']
1
stone-game-vii
Recursion->Memoization->Tabulation
recursion-memoization-tabulation-by-abhi-wbbn
Intuition\n Describe your first thoughts on how to solve this problem. \n\nAlice Turn\n [5 3 1 4 2]\n A = 5 + 3 + 1 + 4 = 13 \nBob Turn\n [
abhisek_
NORMAL
2022-12-31T05:18:58.892710+00:00
2022-12-31T05:18:58.892755+00:00
774
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n```\nAlice Turn\n [5 3 1 4 2]\n A = 5 + 3 + 1 + 4 = 13 \nBob Turn\n [5 3 1 4]\n B = 3 + 1 + 4 = 8\nAlice Turn\n [3 1 4]\n A = 1 + 4 = 5\nBob Turn\n [1 4]\n B = 4 = 4\nResult\n ...
5
0
['Dynamic Programming', 'Recursion', 'Memoization', 'Python3']
0
stone-game-vii
Simple c++ solution using Memoization
simple-c-solution-using-memoization-by-a-m9i2
\nclass Solution {\npublic:\n int t[1001][1001];\n \n int solve(vector<int> &stones, int left, int right, int sum)\n {\n if(left>=right)\n
Amey_Joshi
NORMAL
2021-06-11T13:43:38.262212+00:00
2021-06-11T13:43:38.262253+00:00
459
false
```\nclass Solution {\npublic:\n int t[1001][1001];\n \n int solve(vector<int> &stones, int left, int right, int sum)\n {\n if(left>=right)\n return 0;\n \n if(t[left][right]!=-1)\n return t[left][right];\n \n if(left-right==1)\n return t[l...
5
0
[]
1
stone-game-vii
C++ Super Simple and Clear Solution
c-super-simple-and-clear-solution-by-yeh-rzph
\nclass Solution {\npublic:\n int rec(vector<int>& stones, int start, int end, int sum) {\n if (start == end) \n return 0;\n \n
yehudisk
NORMAL
2021-06-11T09:10:34.599853+00:00
2021-06-11T09:10:34.599889+00:00
312
false
```\nclass Solution {\npublic:\n int rec(vector<int>& stones, int start, int end, int sum) {\n if (start == end) \n return 0;\n \n if (dp[start][end]) \n return dp[start][end];\n \n int remove_first = sum - stones[start] - rec(stones, start+1, end, sum-stones[...
5
1
['C']
0
stone-game-vii
Straight forward DP solution | Memoizaton | c++ | O(n*n)
straight-forward-dp-solution-memoizaton-qdcn4
\nint pre[1005];\nint getsum(int l,int r){\n if(l > r)\n return 0;\n return pre[r] - (l>0?pre[l-1]:0);\n}\n\nint cache[1005][1005][2];\nint dp(int
ghoshashis545
NORMAL
2020-12-13T04:27:34.420403+00:00
2020-12-13T04:27:34.420443+00:00
328
false
```\nint pre[1005];\nint getsum(int l,int r){\n if(l > r)\n return 0;\n return pre[r] - (l>0?pre[l-1]:0);\n}\n\nint cache[1005][1005][2];\nint dp(int l,int r,int f)\n{\n if(l > r)\n return 0;\n int &ans = cache[l][r][f];\n if(ans != -1)\n return ans;\n int lsum = getsum(l,r-1) , r...
5
1
['Memoization']
0
stone-game-vii
C# Simple DP
c-simple-dp-by-leoooooo-n57f
\npublic class Solution\n{\n public int StoneGameVII(int[] stones)\n {\n int sum = stones.Sum();\n return Max(stones, 0, stones.Length - 1,
leoooooo
NORMAL
2020-12-13T04:06:02.016077+00:00
2020-12-13T04:06:54.607874+00:00
301
false
```\npublic class Solution\n{\n public int StoneGameVII(int[] stones)\n {\n int sum = stones.Sum();\n return Max(stones, 0, stones.Length - 1, sum, new int[stones.Length, stones.Length]);\n }\n\n private int Max(int[] stones, int i, int j, int sum, int[,] memo)\n {\n if (i == j) retu...
5
0
[]
1
stone-game-vii
Python3. DP without prefix sum.
python3-dp-without-prefix-sum-by-yarosla-88f6
Idea: make moves of two players as one dp step.\nThere are 4 cases. Consider [a, b, c, x, y, z]. \n1. Player one takes a. \n\t1.1. Player two takes b. Score sum
yaroslav-repeta
NORMAL
2021-06-26T03:15:46.741081+00:00
2021-06-26T03:20:09.970263+00:00
170
false
Idea: make moves of two players as one dp step.\nThere are 4 cases. Consider `[a, b, c, x, y, z]`. \n1. Player one takes `a`. \n\t1.1. Player two takes `b`. Score `sum(b, c, x, y, z) - sum(c, x, y, z) = b`.\n\t1.2. Player two takes `z`. Score `sum(b, c, x, y, z) - sum(b, c, x, y) = z`.\n2. Player one takes `z`.\n\t2.1....
4
0
[]
2
stone-game-vii
Python "Numpy Is The King" solution (Runtime: 220 ms)
python-numpy-is-the-king-solution-runtim-x3nj
Just the same bottom-up solution as any other. But much faster with numpy:\n\n\nimport numpy as np\n\nclass Solution:\n def stoneGameVII(self, stones: List[i
agakishy
NORMAL
2021-06-11T07:58:17.086160+00:00
2021-06-11T18:29:41.514165+00:00
250
false
Just the same bottom-up solution as any other. But much faster with numpy:\n\n```\nimport numpy as np\n\nclass Solution:\n def stoneGameVII(self, stones: List[int]) -> int:\n n = len(stones)\n stones = np.array(stones, dtype = int)\n score = np.zeros(n, dtype = int)\n summ = np.array(ston...
4
1
[]
1
stone-game-vii
C++, memozation, Minimax approach
c-memozation-minimax-approach-by-aditya_-o3tt
\n int memo(vector<vector<int>> & dp, vector<int>& stones, int sum, int start, int end){\n if(sum <= 0) return 0; \n if(start== end )return 0;\
aditya_trips
NORMAL
2021-01-16T13:26:49.377724+00:00
2021-01-16T13:26:49.377754+00:00
689
false
```\n int memo(vector<vector<int>> & dp, vector<int>& stones, int sum, int start, int end){\n if(sum <= 0) return 0; \n if(start== end )return 0;\n if(dp[start][end]!= -1)return dp[start][end]; \n \n int res = max(sum-stones[start]- memo(dp,stones, sum-stones[start], start+1, end),...
4
0
['Recursion', 'Memoization', 'C']
0
stone-game-vii
Java O(n^2) bottom up solution with detailed explanation. No prefix sum
java-on2-bottom-up-solution-with-detaile-wp17
Considering array [a1,a2,...,an-1,an]\n\nIf Alice takes a1, then Alice gains sum(a2,...,an) score. Bob takes either a2 or an, which gives him either sum(a3,...,
datou12138
NORMAL
2020-12-29T12:50:36.506202+00:00
2020-12-29T12:50:36.506250+00:00
231
false
Considering array [a1,a2,...,an-1,an]\n\nIf Alice takes `a1`, then Alice gains `sum(a2,...,an)` score. Bob takes either `a2` or `an`, which gives him either `sum(a3,...,an)` score or `sum(a2,...,an-1)` score, hence the difference is either `a2` or` an`. Since Bob wants to minimize the difference, he should take `min(a...
4
0
[]
0
stone-game-vii
DP SOLUTION W/O TURN TRACKING || EASY TO UNDERSTAND
dp-solution-wo-turn-tracking-easy-to-und-v9uf
At first glance this solution might look like we are just returning the max score by which Alice will win, \nHere Bob will follow the approach to maximise diffe
mehta_
NORMAL
2020-12-13T04:23:21.057898+00:00
2020-12-13T07:42:05.234203+00:00
736
false
At first glance this solution might look like we are just returning the max score by which Alice will win, \nHere Bob will follow the approach to maximise difference at his play so he will then minimize Alice\'s score when she picked the stone before his turn.\nalicePreviousPickDiff = optimalPickByAlice - bobNextPickDi...
4
1
['Dynamic Programming', 'Java']
4
stone-game-vii
Recursion | Memoization | Tabulation ✅
recursion-memoization-tabulation-by-shad-yaj6
_____\n\nUp Vote if Helps\n\n_____\n\n# Recursion: 1 TLE \n\nclass Solution { \n public int stoneGameVII(int[] stones) {\n int totalSum=0;\n fo
Shadab_Ahmad_Khan
NORMAL
2023-10-06T16:56:48.224404+00:00
2023-10-06T16:57:53.030974+00:00
359
false
______________________________________\n\n**Up Vote if Helps**![image.png](https://assets.leetcode.com/users/images/23d8443e-ac59-49d5-99f0-9273a2147be2_1687635435.0337658.png)\n\n______________________________________\n\n# Recursion: 1 *TLE* \n```\nclass Solution { \n public int stoneGameVII(int[] stones) {\n ...
3
0
['Dynamic Programming', 'Recursion', 'Memoization', 'Java']
0
stone-game-vii
C++ || Memoization || Easy to Understand
c-memoization-easy-to-understand-by-yash-z9x9
```\nclass Solution {\npublic:\n int solve(vector &a,int i,int j,int sum,bool isAliceTurn,vector> &dp)\n {\n if(i>j)\n {\n // if
yashagrawal81930
NORMAL
2021-09-10T05:39:19.850344+00:00
2021-09-10T05:39:19.850379+00:00
236
false
```\nclass Solution {\npublic:\n int solve(vector<int> &a,int i,int j,int sum,bool isAliceTurn,vector<vector<int>> &dp)\n {\n if(i>j)\n {\n // if there is no element in array then Alice and Bob\'s scores are 0\n // So the difference is also 0\n return 0;\n }\n...
3
0
[]
1
stone-game-vii
C++ Solution || DP || Easy Understanding
c-solution-dp-easy-understanding-by-kann-jbwj
\nclass Solution {\npublic:\n int helper(int l, int r, vector<int>& stones, int sum, vector<vector<int>>& dp){\n if(l == r) return 0; //array has 1 el
kannu_priya
NORMAL
2021-06-11T17:51:26.325475+00:00
2021-06-11T17:51:52.841082+00:00
391
false
```\nclass Solution {\npublic:\n int helper(int l, int r, vector<int>& stones, int sum, vector<vector<int>>& dp){\n if(l == r) return 0; //array has 1 element\n if(r-l == 1) return max(stones[l], stones[r]); // array has 2 elements\n if(dp[l][r] != -1) return dp[l][r]; //memorization\n in...
3
0
['Dynamic Programming', 'C', 'C++']
0
stone-game-vii
[Python] O(n^2) Accepted Submission (with comments)
python-on2-accepted-submission-with-comm-mhj7
\nclass Solution:\n def stoneGameVII(self, stones: List[int]) -> int:\n n = len(stones)\n if n==0:\n return 0\n total = sum(s
rajat499
NORMAL
2021-06-11T17:02:12.619184+00:00
2021-06-11T17:02:12.619228+00:00
115
false
```\nclass Solution:\n def stoneGameVII(self, stones: List[int]) -> int:\n n = len(stones)\n if n==0:\n return 0\n total = sum(stones)\n \n dp = [[-1]*n for _ in range(n)]\n ##Maximum difference the current player can achieve when stones[i:j](included) are left\n ...
3
0
[]
0
stone-game-vii
Whoever thought that I would see this day, that python wouldn't pass and java would make way.
whoever-thought-that-i-would-see-this-da-7yei
\nclass Solution {\n \n static int solve(int i,int j , int score,int [] stones,int [][] dp){\n if (i == stones.length || j < 0 ){\n retu
bismeet
NORMAL
2021-06-11T08:54:45.870430+00:00
2021-06-11T08:54:45.870462+00:00
446
false
```\nclass Solution {\n \n static int solve(int i,int j , int score,int [] stones,int [][] dp){\n if (i == stones.length || j < 0 ){\n return 0;\n }\n if (dp[i][j]!=-1){\n return dp[i][j];\n }\n int best = 0;\n int op1 = score - stones[i] - solve(i+1...
3
0
['Java']
1
stone-game-vii
[JAVA] Dp + Memoization
java-dp-memoization-by-ziddi_coder-y3r5
\tclass Solution {\n\t\tpublic int stoneGameVII(int[] stones) {\n\n\t\t\tint n = stones.length, sum = 0;\n\n\t\t\tint[][] dp = new int[n][n];\n\n\t\t\tfor(int i
Ziddi_Coder
NORMAL
2020-12-13T08:40:41.381237+00:00
2020-12-13T08:41:03.894339+00:00
177
false
\tclass Solution {\n\t\tpublic int stoneGameVII(int[] stones) {\n\n\t\t\tint n = stones.length, sum = 0;\n\n\t\t\tint[][] dp = new int[n][n];\n\n\t\t\tfor(int i = 0;i<n;i++) \n\t\t\t Arrays.fill(dp[i], -1);\n\n\t\t\tfor(int i = 0;i<n;i++) \n\t\t\t sum += stones[i];\n\n\t\t\treturn solve(0, n-1, stones, sum, dp);\...
3
0
[]
0
stone-game-vii
Interval dynamic programming solution with tracing bottom-up approach
interval-dynamic-programming-solution-wi-sniz
IntuitionThis problem falls under Interval DP problem, where we progressively break down a larger interval into smaller intervals. The idea is to compute the op
MO-Harm
NORMAL
2025-03-01T13:35:00.766696+00:00
2025-03-01T13:35:00.766696+00:00
83
false
# Intuition This problem falls under [Interval DP problem](https://algo.monster/problems/dp_interval_intro), where we progressively break down a larger interval into smaller intervals. The idea is to compute the optimal strategy for Alice and Bob as they remove stones from either end. # Approach 1. Compute the prefix ...
2
0
['Dynamic Programming', 'Java']
0
stone-game-vii
✅✅Faster || Easy To Understand || C++ Code
faster-easy-to-understand-c-code-by-__kr-b1s3
Recursion && Memoization\n\n Time Complexity :- O(N * N)\n\n Space Complexity :- O(N * N)\n\n\nclass Solution {\npublic:\n \n // declare a prefix array\n
__KR_SHANU_IITG
NORMAL
2022-09-16T07:00:14.174220+00:00
2022-09-16T07:00:14.174262+00:00
1,303
false
* ***Recursion && Memoization***\n\n* ***Time Complexity :- O(N * N)***\n\n* ***Space Complexity :- O(N * N)***\n\n```\nclass Solution {\npublic:\n \n // declare a prefix array\n \n vector<int> prefix_sum;\n \n // declare a dp\n \n vector<vector<int>> dp;\n \n int helper(vector<int>& stone...
2
0
['Dynamic Programming', 'Recursion', 'Memoization', 'C', 'C++']
0
stone-game-vii
C++ || RECURSION + MEMOIZATION + PREFIX_SUM
c-recursion-memoization-prefix_sum-by-ea-lafm
```\nclass Solution {\npublic:\n int dp[1001][1001];\n \n \n int solve(vector& stones, int i, int j, vector& pre_sum){\n if(i >= j) return 0;
Easy_coder
NORMAL
2022-03-29T15:55:24.248201+00:00
2022-03-29T15:55:24.248246+00:00
291
false
```\nclass Solution {\npublic:\n int dp[1001][1001];\n \n \n int solve(vector<int>& stones, int i, int j, vector<int>& pre_sum){\n if(i >= j) return 0;\n if(i + 1 == j) return max(stones[i], stones[j]);\n if(dp[i][j] != -1) return dp[i][j];\n // option 1 to choose the ith index...
2
0
['Recursion', 'Memoization', 'C', 'Prefix Sum']
0
stone-game-vii
Cpp solution Recursion/DP (beats 98%/97%)
cpp-solution-recursiondp-beats-9897-by-d-le9x
Let the total sum of elements in array be "sum", then if Alice selects (say) i\'th element then Alice\'s current score is "sum-stones[i]". Now if Bob selects sa
dreamer4346
NORMAL
2021-06-12T09:57:52.065461+00:00
2021-06-12T09:58:52.273502+00:00
115
false
Let the total sum of elements in array be "sum", then if Alice selects (say) i\'th element then Alice\'s current score is **"sum-stones[i]"**. Now if Bob selects say some k\'th element (which can be either i+1\'th or j\'th) then Bob\'s current score would be Alice\'s current-stones[k], i.e.**"sum-stones[i]-stones[k]"**...
2
0
[]
0
stone-game-vii
Top Down, C++ | Simple
top-down-c-simple-by-digbick_17-r0nd
Calculate the difference directly by subtracting the optimal value chosen by the other player. Store the redundant states in a table.\n\nclass Solution {\npubli
DigBick_17
NORMAL
2021-06-11T19:24:59.394297+00:00
2021-06-12T05:57:43.090213+00:00
270
false
Calculate the difference directly by subtracting the optimal value chosen by the other player. Store the redundant states in a table.\n```\nclass Solution {\npublic:\n vector<vector<int>> dp;\n int stoneGameVII(vector<int>& stones) {\n dp.resize(stones.size(),vector<int>(stones.size(),-1));\n int to...
2
0
['Dynamic Programming', 'C', 'C++']
0
stone-game-vii
Python [Top-down DP]
python-top-down-dp-by-gsan-4j50
I think this is a quite difficult question even if the code itself is short. We need to use dynamic programming and in order to avoid tracking the solution path
gsan
NORMAL
2021-06-11T09:11:32.550211+00:00
2021-06-11T09:12:50.615928+00:00
143
false
I think this is a quite difficult question even if the code itself is short. We need to use dynamic programming and in order to avoid tracking the solution path for both Alice and Bob the DP should be on differences. \n\nIf we let `dp(i, j)` to be the best possible move for any player\'s turn, then this depends on sele...
2
2
[]
1
stone-game-vii
[Python] Space optimized DP: 99% speed
python-space-optimized-dp-99-speed-by-kc-9vjb
This problem is almost equivalent to problem 486, and even has the same DP equation:\nDP[i][j] is the difference in scores between the next player to move and t
kcsquared
NORMAL
2021-03-27T14:01:02.172873+00:00
2021-03-27T14:01:02.172912+00:00
275
false
This problem is almost equivalent to [problem 486](https://leetcode.com/problems/predict-the-winner/), and even has the same DP equation:\nDP[i][j] is the difference in scores between the next player to move and the other player on the array stones[i .. j]. Then we get\nDP[i][j] = max(score for choosing i - DP[i+1][j],...
2
0
['Dynamic Programming', 'Python']
0
stone-game-vii
C++ with logic explanation
c-with-logic-explanation-by-apun_ko_leve-h6cp
Both players want to MAXIMISE difference. \nIt says B wants to minimize absolute difference wrt A, but if consider max() on negative numbers, the lower absolute
apun_ko_level_badhane_ka
NORMAL
2021-01-29T10:42:16.377369+00:00
2021-01-29T11:20:52.223220+00:00
218
false
Both players want to MAXIMISE difference. \nIt says B wants to minimize absolute difference wrt A, but if consider max() on negative numbers, the lower absolute difference gets picked anyway. \n\nSince both players have the same objective (to maximize difference in score), whose chance it is does not matter.\n\nAssumin...
2
0
[]
0
stone-game-vii
java memo
java-memo-by-prateekvortex-r4rs
\nclass Solution {\n int dp[][];\n int help(int arr[],int start,int end,int total){\n if(start>end)\n return 0;\n if(dp[start][en
prateekvortex
NORMAL
2021-01-20T12:18:22.647327+00:00
2021-01-20T12:18:22.647357+00:00
336
false
```\nclass Solution {\n int dp[][];\n int help(int arr[],int start,int end,int total){\n if(start>end)\n return 0;\n if(dp[start][end]!=-1)\n return dp[start][end];\n \n \n return dp[start][end]= Math.max(total-arr[start]-help(arr,start+1,end,total-arr[star...
2
0
['Memoization', 'Java']
1
stone-game-vii
Javascript | Simple DP (no prefix sum needed) Solution | beats 100%
javascript-simple-dp-no-prefix-sum-neede-m6y9
Create a dynamic programming solution matrix dp filled with solutions dp[i][j] where i and j represent the left and right positions of the remaining stones.\n\n
sgallivan
NORMAL
2020-12-29T19:31:20.112300+00:00
2020-12-29T19:36:10.859678+00:00
208
false
Create a dynamic programming solution matrix **dp** filled with solutions **dp[i][j]** where **i** and **j** represent the left and right positions of the remaining stones.\n\nIterate through **i** backwards in order to avoid having to build a prefix sum array beforehand, as you can just increment the **sum** value as ...
2
0
['Dynamic Programming', 'JavaScript']
0
stone-game-vii
Javascript Memoization with clear code
javascript-memoization-with-clear-code-b-uzis
The main point is spotting the subproblem.\n\nOptimal diff with array between i, j = Max(\n Score when i + 1 is removed - Optimal diff with array between i +
itssumitrai
NORMAL
2020-12-14T19:09:53.205052+00:00
2020-12-14T19:10:29.295924+00:00
148
false
The main point is spotting the subproblem.\n\nOptimal diff with array between i, j = Max(\n Score when i + 1 is removed - Optimal diff with array between i + 1,j,\n Score when j - 1 is removed - Optimal diff with array between i, j - 1\n);\nIts a simple recursion equation at this point, and there would be alot of...
2
0
[]
0
stone-game-vii
[Python] Clear DFS Solution with Video Explanation
python-clear-dfs-solution-with-video-exp-hia8
Video with clear visualization and explanation:\nhttps://youtu.be/MwLSDvmkGGY\n\n\n\nIntuition: dfs+memo\n\n\nCode\nInspired by https://leetcode.com/problems/st
iverson52000
NORMAL
2020-12-13T21:38:31.193235+00:00
2020-12-13T21:38:31.193288+00:00
371
false
Video with clear visualization and explanation:\nhttps://youtu.be/MwLSDvmkGGY\n\n\n\nIntuition: dfs+memo\n\n\n**Code**\nInspired by https://leetcode.com/problems/stone-game-vii/discuss/970268/C%2B%2BPython-O(n-*-n)\n```\nfrom itertools import accumulate\n\nclass Solution:\n def stoneGameVII(self, stones: List[int]) ...
2
0
['Python']
1
stone-game-vii
C++, Top-Down DP, O(n*n), Basic logic of game solving
c-top-down-dp-onn-basic-logic-of-game-so-iue5
Logic used - \n1. Every time a player has to make a turn, he/she has 2 choices i.e whether to start from leftmost element or the rightmost element.\n2. Alice is
kakashi_98
NORMAL
2020-12-13T08:20:02.344915+00:00
2020-12-13T08:20:02.344951+00:00
213
false
Logic used - \n1. Every time a player has to make a turn, he/she has 2 choices i.e whether to start from leftmost element or the rightmost element.\n2. Alice is trying to increase the difference so his score at every step will always be to "add" to the overall difference, so take the MAX of the 2 next states, choosing ...
2
1
['Dynamic Programming', 'C']
2
stone-game-vii
JAVA | DP | 6% |
java-dp-6-by-idbasketball08-n21l
```\nclass Solution {\n public int stoneGameVII(int[] stones) {\n //strategy: DP\n //precompute the sum\n int sum = 0;\n for (int
idbasketball08
NORMAL
2020-12-13T04:20:05.641427+00:00
2020-12-14T04:32:28.142491+00:00
228
false
```\nclass Solution {\n public int stoneGameVII(int[] stones) {\n //strategy: DP\n //precompute the sum\n int sum = 0;\n for (int stone : stones) {\n sum += stone;\n }\n int n = stones.length;\n Integer[][][] dp = new Integer[n][n][2];\n return helpe...
2
0
[]
1
stone-game-vii
Python -- recursion approach
python-recursion-approach-by-zebratiger4-n35q
def helper(self,stone,tmp=0):\n \n if not stone:\n return 0\n \n \n \n left = tmp - stone[-1] - self.helper
zebratiger4
NORMAL
2020-12-13T04:17:45.672975+00:00
2020-12-13T04:17:45.673020+00:00
163
false
def helper(self,stone,tmp=0):\n \n if not stone:\n return 0\n \n \n \n left = tmp - stone[-1] - self.helper(stone[:-1],tmp - stone[-1]) \n right = tmp - stone[0] - self.helper(stone[1:], tmp - stone[0])\n \n \n return max(left,right) ...
2
0
[]
0
stone-game-vii
Python 3 Simple DP Solution in O(n^2)
python-3-simple-dp-solution-in-on2-by-d_-vg10
Similar to what we saw in previous Stone Game, we can take use of choosing from the left/right margin. In each turn, no matter who is choosing, we want to find
d_8023_k
NORMAL
2020-12-13T04:08:57.504555+00:00
2020-12-13T04:08:57.504589+00:00
110
false
Similar to what we saw in previous Stone Game, we can take use of choosing from the left/right margin. In each turn, no matter who is choosing, we want to find the optimal case:\n```\nclass Solution:\n def stoneGameVII(self, stones: List[int]) -> int:\n length = len(stones)\n csum = [0 for _ in range(l...
2
1
[]
1
stone-game-vii
[Python] O(n^2) Dynamic Programming
python-on2-dynamic-programming-by-delphi-p48v
Python code:\npython\ndef stoneGameVII(self, A: List[int]) -> int:\n n = len(A)\n pref_s = A.copy() # prefix sum\n for i in range(1, n):\n pref
delphih
NORMAL
2020-12-13T04:01:26.804372+00:00
2020-12-13T04:01:26.804421+00:00
600
false
## Python code:\n```python\ndef stoneGameVII(self, A: List[int]) -> int:\n n = len(A)\n pref_s = A.copy() # prefix sum\n for i in range(1, n):\n pref_s[i] += pref_s[i-1]\n pref_s.append(0)\n dp = [0] * n\n for step in range(2, n+1):\n for i in range(n-1, step-2, -1):\n dp[i] ...
2
0
['Dynamic Programming', 'Python']
0
stone-game-vii
Minimax Approach with Dual Caching for Stone Game VII
minimax-approach-with-dual-caching-for-s-umov
\n# Approach\n Describe your approach to solving the problem. \nThis solution applies a minimax algorithm to solve the Stone Game VII problem, utilizing distinc
_LaVa
NORMAL
2024-08-21T10:09:02.330021+00:00
2024-08-21T10:09:02.330062+00:00
153
false
\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThis solution applies a minimax algorithm to solve the Stone Game VII problem, utilizing distinct caches for Alice and Bob. The approach involves:\n\n- **Prefix Sum Array:** To efficiently calculate the total sum of stones between any two indices.\n...
1
0
['Python3']
0
stone-game-vii
Easy to Unuderstand || Top Down Solution || Game Theory
easy-to-unuderstand-top-down-solution-ga-m8ag
Intuition\nThe problem at hand involves finding the maximum score difference between two players, Alice and Bob, in a game where they take turns selecting stone
tinku_tries
NORMAL
2024-06-03T07:12:11.467066+00:00
2024-06-03T07:12:11.467086+00:00
380
false
# Intuition\nThe problem at hand involves finding the maximum score difference between two players, Alice and Bob, in a game where they take turns selecting stones from either end of a row. The score for each player is determined by the sum of the stones they select. To solve this, we can use dynamic programming to com...
1
0
['Array', 'Math', 'Dynamic Programming', 'Game Theory', 'C++']
0
stone-game-vii
Simple Recursion, there are 2 choices || Hindi Comments
simple-recursion-there-are-2-choices-hin-e128
Intuition\n Describe your first thoughts on how to solve this problem. \nGame theory ka yhi basics h ki apna max bnao aur saamne wle se expect kro ki vo tumhe w
vaibhavsingh18
NORMAL
2023-10-07T06:24:50.320240+00:00
2023-10-07T06:24:50.320261+00:00
133
false
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nGame theory ka yhi basics h ki apna max bnao aur saamne wle se expect kro ki vo tumhe worst ans laake dega, uske baad bs recursion h \n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:...
1
0
['Dynamic Programming', 'Recursion', 'Memoization', 'Game Theory', 'C++']
1
stone-game-vii
Time 100% and Memory 100%
time-100-and-memory-100-by-fredrick_li-64qz
Intuition\nNotice that the difference of scores is the sum of all the stones that Bob takes, so for both Alice and Bob, their optimal strategy is to minimize th
Fredrick_LI
NORMAL
2023-07-27T06:21:20.516288+00:00
2023-07-27T06:21:20.516311+00:00
151
false
# Intuition\nNotice that the difference of scores is the sum of all the stones that Bob takes, so for both Alice and Bob, their optimal strategy is to minimize their own sums of stones.\n\n# Approach\nUse dynamic programming from the last step to the first.\n\n# Complexity\n- Time complexity:\n$O(n^2)$\n\n- Space compl...
1
0
['Python3']
1
stone-game-vii
C++ || Bawaal Question || Fully Explained Intuitions || Memoization || DP
c-bawaal-question-fully-explained-intuit-gnxi
\n// Bawwal Question \n \n // A -> only one element , ans = 0;\n \n // AB -> if we will remove A , we will take B \n // if we will remove
KR_SK_01_In
NORMAL
2022-08-19T07:18:31.747718+00:00
2022-08-19T07:19:53.187869+00:00
340
false
```\n// Bawwal Question \n \n // A -> only one element , ans = 0;\n \n // AB -> if we will remove A , we will take B \n // if we will remove B , we will take A , ans=max(A , B) in this case\n \n // ABC -> Case 1 if we will remove A , then it will be like B + C - max(func(BC))\n // ...
1
0
['Dynamic Programming', 'Memoization', 'C']
2
stone-game-vii
C++ || Top down || Bottom up || Detailed Explanation || Beginner Friendly
c-top-down-bottom-up-detailed-explanatio-pgqq
Code:\n\nTop-Down:\n\n\nclass Solution\n{\npublic:\n vector<vector<int>> memo;\n vector<int> preSum;\n int getSum(int i, int j)\n {\n return
anis23
NORMAL
2022-07-20T04:47:18.298285+00:00
2022-07-20T04:49:19.909025+00:00
457
false
**Code:**\n\n**Top-Down:**\n\n```\nclass Solution\n{\npublic:\n vector<vector<int>> memo;\n vector<int> preSum;\n int getSum(int i, int j)\n {\n return preSum[j + 1] - preSum[i];\n }\n int dp(int i, int j)\n {\n if (i == j)\n return 0; // only 1 stone, score = 0 -> differen...
1
0
['Dynamic Programming', 'Memoization', 'C', 'C++']
0
stone-game-vii
C++ Fully Explained | Without Prefix Sum
c-fully-explained-without-prefix-sum-by-bl915
There is no need to calculate prefix sum.\nFor.eg. Let\'s say the array is\n a1, a2, a3, a4\n\nNow consider alice picks a1\n Again consider bob picks a2,
mjustboring
NORMAL
2022-07-15T19:56:41.700744+00:00
2022-07-15T20:00:39.128460+00:00
150
false
There is no need to calculate prefix sum.\nFor.eg. Let\'s say the array is\n a1, a2, a3, a4\n\nNow consider alice picks a1\n Again consider bob picks a2, then diff will be\n (a2 + a3 + a4) - (a3 + a4) = a2\n i.e. the element which bob picked.\n\nIt can also be checked for others that the difference\...
1
0
[]
0
stone-game-vii
Java Top Down DP Solution
java-top-down-dp-solution-by-zaidzack-jynp
\nclass Solution {\n int[][] dp;\n public int stoneGameVII(int[] stones) {\n int len = stones.length;\n dp = new int[len][len];\n \n
zaidzack
NORMAL
2022-07-04T18:48:14.494161+00:00
2022-07-04T18:48:14.494199+00:00
70
false
```\nclass Solution {\n int[][] dp;\n public int stoneGameVII(int[] stones) {\n int len = stones.length;\n dp = new int[len][len];\n \n int sum = 0;\n for(int n: stones)\n sum += n;\n \n for(int[] row: dp)\n Arrays.fill(row, -1);\n \n ...
1
0
['Dynamic Programming', 'Memoization', 'Java']
1
stone-game-vii
C++ || EASY TO UNDERSTAND || Memoization
c-easy-to-understand-memoization-by-aari-c8ii
\nclass Solution {\npublic:\n int helper(int i,int j,int sum,vector<int> &stones,vector<vector<int>> &dp)\n {\n if(i>j)\n return 0;\n
aarindey
NORMAL
2022-04-14T13:47:02.390058+00:00
2022-04-14T13:47:21.102585+00:00
137
false
```\nclass Solution {\npublic:\n int helper(int i,int j,int sum,vector<int> &stones,vector<vector<int>> &dp)\n {\n if(i>j)\n return 0;\n if(dp[i][j]!=-1)\n {\n return dp[i][j];\n }\n return dp[i][j]=max(sum-stones[i]-helper(i+1,j,sum-stones[i],stones,dp),su...
1
0
[]
0
stone-game-vii
c++|| DP || memoization || Easy to understand
c-dp-memoization-easy-to-understand-by-s-llja
\nclass Solution {\npublic:\n int fun(vector<int>& stones,int i,int j,int sum,vector<vector<int>>&dp)\n {\n if(i>j) return 0;\n \n if
soujash_mandal
NORMAL
2022-04-14T13:36:14.567387+00:00
2022-04-14T13:36:14.567432+00:00
76
false
```\nclass Solution {\npublic:\n int fun(vector<int>& stones,int i,int j,int sum,vector<vector<int>>&dp)\n {\n if(i>j) return 0;\n \n if(dp[i][j]!=-1) return dp[i][j];\n \n int res=0;\n res=max(res,(sum-stones[i])-fun(stones,i+1,j,sum-stones[i],dp));\n res=max(res,...
1
0
[]
1
stone-game-vii
C++ || Bottom-up DP || Beats 99% time and 97% memory
c-bottom-up-dp-beats-99-time-and-97-memo-f0es
Regardless of the problem description, both the strategies of Alice and Bob are the same.\nMaximize the difference(From Bob\'s perspective, difference is define
walaohye
NORMAL
2022-04-04T04:49:45.187469+00:00
2022-04-04T05:08:40.775795+00:00
57
false
Regardless of the problem description, both the strategies of Alice and Bob are the same.\n**Maximize the difference(From Bob\'s perspective, difference is defined as Bob\'s score - Alice\'s score) given the remaing stones**\n```\nint stoneGameVII(vector<int>& stones) {\n int n = stones.size();\n\t\t// Initializ...
1
0
[]
0
stone-game-vii
C++| Topdown Tree Traversal + Memoization | Lots of explanation.
c-topdown-tree-traversal-memoization-lot-38qh
The result of the each turns follows a decision tree:\n\n each turn\'s result is the value of piles[left] or piles[right]\n left, right value follows a patterns
freewind1986
NORMAL
2022-03-17T04:50:44.103708+00:00
2022-03-17T06:21:39.328788+00:00
64
false
The result of the each turns follows a decision tree:\n\n* each turn\'s result is the value of piles[left] or piles[right]\n* left, right value follows a patterns: if a left stone is taken, the next left is left+1; if a right stone is taken, the next right is right-1\n* each turn is called recursively:\n```\nscore = pl...
1
0
[]
0
stone-game-vii
Simple and Precise | Simple | Recursive | Intuitive | Beginners Game Strategy
simple-and-precise-simple-recursive-intu-3cjj
```\nclass Solution {\npublic:\n vector> dp;\n int fun(int i,int j,vector &arr,vector &pre){\n //Base Case \n if(i +1== j){\n ret
njcoder
NORMAL
2022-03-06T13:44:21.185229+00:00
2022-03-06T13:44:21.185268+00:00
102
false
```\nclass Solution {\npublic:\n vector<vector<int>> dp;\n int fun(int i,int j,vector<int> &arr,vector<int> &pre){\n //Base Case \n if(i +1== j){\n return max(arr[i],arr[i+1]);\n }\n if(i == j) return 0;\n if(i > j) return 0;\n if(dp[i][j] != -1) return dp[i][j...
1
0
['Dynamic Programming', 'Recursion']
0
stone-game-vii
From Recursion to Memoization | CPP | Extremely Simple
from-recursion-to-memoization-cpp-extrem-tw22
\nint f(vector<int>stones, int i,int j,int sum){\n if(sum<=0 || i==j) return 0;\n \n return max((sum-stones[i])- f(stones,i+1,j,sum-stones[
sarora160
NORMAL
2022-01-19T08:54:41.930204+00:00
2022-01-19T08:54:41.930293+00:00
154
false
```\nint f(vector<int>stones, int i,int j,int sum){\n if(sum<=0 || i==j) return 0;\n \n return max((sum-stones[i])- f(stones,i+1,j,sum-stones[i]),\n (sum-stones[j]) - f(stones,i,j-1, sum-stones[j]));\n }\n int stoneGameVII(vector<int>& stones) {\n int sum{accumulate(s...
1
0
['C', 'C++']
0
stone-game-vii
Go | DP | Beat 100%
go-dp-beat-100-by-linhduong-wztp
\nfunc stoneGameVII(stones []int) int {\n sum := buildPrefixSum(stones) \n \n var (\n prev, current [2][]int\n n = len(stones)\n )\n
linhduong
NORMAL
2021-12-14T12:16:06.043192+00:00
2021-12-14T12:16:06.043227+00:00
86
false
```\nfunc stoneGameVII(stones []int) int {\n sum := buildPrefixSum(stones) \n \n var (\n prev, current [2][]int\n n = len(stones)\n )\n \n\t// prev and current is pivot dp slice which store difference of each state\n\t//\n\t// 0: Alice move\n\t// 1: Bob move\n prev[0], prev[1] = make([]i...
1
0
['Go']
0
stone-game-vii
[JAVA] Easy and Clean DP (Tabulation) Solution
java-easy-and-clean-dp-tabulation-soluti-97zd
Time Complexity - O(N^2)\nSpcae Complexity - O(N^2)\nRuntime - 37ms - Faster than 90.16%\n.\n\nclass Solution {\n public int stoneGameVII(int[] stones) {\n
Dyanjno123
NORMAL
2021-11-27T17:29:52.470039+00:00
2021-11-27T17:30:26.020147+00:00
151
false
Time Complexity - O(N^2)\nSpcae Complexity - O(N^2)\nRuntime - 37ms - Faster than 90.16%\n.\n```\nclass Solution {\n public int stoneGameVII(int[] stones) {\n int[][] dp = new int[stones.length][stones.length];\n int[] pre = new int[stones.length];\n pre[0] = stones[0];\n for(int i = 1; i...
1
0
['Dynamic Programming', 'Java']
0
stone-game-vii
C++ || TWO METHODS || RECURSION + MEMOIZATION || BOTTOM-UP DP
c-two-methods-recursion-memoization-bott-3moz
METHOD --> 1 \n\nint dp[1005][1005];\n \n int func(vector&nums,vector&prefix,int i,int j){\n \n if(i>=j){\n return 0;\n }\
anu_2021
NORMAL
2021-11-07T18:49:12.398384+00:00
2021-11-07T18:49:12.398417+00:00
114
false
# **METHOD --> 1 **\n\nint dp[1005][1005];\n \n int func(vector<int>&nums,vector<int>&prefix,int i,int j){\n \n if(i>=j){\n return 0;\n }\n \n if(dp[i][j]!=-1){\n return dp[i][j];\n }\n \n return dp[i][j]=max(prefix[j+1]-prefix[i+1]-fun...
1
1
[]
0
stone-game-vii
C++ DP with explanation (easy)
c-dp-with-explanation-easy-by-uttu_dce-ipot
\n\t\nf(i, j, stones) : denotes the maximum lead that the current player can take while playing in the subarray stones[i...j] / or how ahead can the current pl
uttu_dce
NORMAL
2021-10-17T08:58:58.184870+00:00
2021-10-17T09:00:40.050829+00:00
145
false
\n\t\n**f(i, j, stones) : denotes the maximum lead that the current player can take while playing in the subarray stones[i...j] / or how ahead can the current player reach from the opponent given that both play optimally**\n\t\nAt any instant, the player whose turn it is currently, will try and take maximum lead (mean...
1
0
[]
0
stone-game-vii
Python, C++ || DP || Prefix Sum || O(N^2)
python-c-dp-prefix-sum-on2-by-in_sidious-j2ms
Python ->\n\nclass Solution:\n def stoneGameVII(self, stones: List[int]) -> int:\n n=len(stones)\n prefix_Sum={-1:0}\n for i,val in enum
iN_siDious
NORMAL
2021-08-23T09:06:37.987246+00:00
2021-08-23T09:07:16.222133+00:00
290
false
Python ->\n```\nclass Solution:\n def stoneGameVII(self, stones: List[int]) -> int:\n n=len(stones)\n prefix_Sum={-1:0}\n for i,val in enumerate(stones):\n prefix_Sum[i]=prefix_Sum[i-1]+val\n dp=[[0]*n for _ in range(n)]\n for i in range(n-1,-1,-1):\n for j in...
1
0
['Dynamic Programming', 'C', 'Prefix Sum', 'Python']
1
stone-game-vii
✔️ [C++] [DP] Simple, Concise and easy to understand code.
c-dp-simple-concise-and-easy-to-understa-o0g9
null
f20180944
NORMAL
2021-08-12T14:30:37.065336+00:00
2021-08-12T14:33:14.366413+00:00
238
false
[<iframe src="https://leetcode.com/playground/8HxADGfL/shared" frameBorder="0" width="900" height="409"></iframe>](http://)
1
0
['Dynamic Programming', 'Memoization']
1
stone-game-vii
C++ Solution explained and commented
c-solution-explained-and-commented-by-pr-bpey
\nclass Solution {\npublic:\n /*\nLogic:Alice and Bob have to choose from either of the left or right most part \nand then his score will become sum of the r
pragya_anand
NORMAL
2021-08-11T14:43:47.537048+00:00
2021-08-11T14:43:47.537097+00:00
261
false
```\nclass Solution {\npublic:\n /*\nLogic:Alice and Bob have to choose from either of the left or right most part \nand then his score will become sum of the remainning stone .So for this we \nneed to first calculate sum for the stones vector and then you have two choices--->\n 1)choose left stone and then score...
1
0
['Dynamic Programming', 'Recursion', 'Memoization', 'C', 'C++']
0
stone-game-vii
kotlin - dp using memo
kotlin-dp-using-memo-by-sandeep549-9p3e
\n fun stoneGameVII(stones: IntArray): Int {\n val sum = stones.sum()\n val memo = Array(stones.size){IntArray(stones.size){-1} }\n retu
sandeep549
NORMAL
2021-08-07T17:04:10.182556+00:00
2021-08-07T17:04:10.182599+00:00
47
false
```\n fun stoneGameVII(stones: IntArray): Int {\n val sum = stones.sum()\n val memo = Array(stones.size){IntArray(stones.size){-1} }\n return play(stones, 0, stones.lastIndex, sum, memo)\n }\n\n fun play(stones: IntArray, l:Int, r: Int, sum: Int, memo: Array<IntArray>) : Int {\n if(...
1
0
[]
0
stone-game-vii
C++ | O(n2) | DP solution
c-on2-dp-solution-by-sp140-q9ls
dp[i][j].first = maximum difference we can get for the sub-array of [i, j], it is Alice\'s turn.\n\ndp[i][j].second = min difference we can get for the sub-arra
sp140
NORMAL
2021-07-24T10:04:29.922236+00:00
2021-07-24T10:04:29.922291+00:00
119
false
dp[i][j].first = maximum difference we can get for the sub-array of [i, j], it is Alice\'s turn.\n\ndp[i][j].second = min difference we can get for the sub-array of [i, j], it is Bob\'s turn.\n\nhence, \ndp[i][j].first = max(dp[i+1][j].second + (sum of the elements[i+1 to j]), dp[i][j-1] + (sum of the elements[i to j-1...
1
0
[]
0
stone-game-vii
[C++] Easy to understand clean & concise dynamic programming one pass O(n*n)
c-easy-to-understand-clean-concise-dynam-7lsx
Please upvote if it helps!\n\nclass Solution {\npublic:\n int sum(vector<int>& a, int i, int j)\n {\n if(i>j)\n return 0;\n if(i=
somurogers
NORMAL
2021-06-21T02:30:20.213321+00:00
2021-06-21T02:30:20.213353+00:00
267
false
Please upvote if it helps!\n```\nclass Solution {\npublic:\n int sum(vector<int>& a, int i, int j)\n {\n if(i>j)\n return 0;\n if(i==0)\n return a[j];\n return a[j]-a[i-1];\n }\n \n int stoneGameVII(vector<int>& stones) {\n int n=stones.size();\n f...
1
0
['Dynamic Programming', 'C', 'C++']
0
stone-game-vii
C++ SOLUTION WITH DP(MEMOIZATION)
c-solution-with-dpmemoization-by-shruti_-w7hc
\nclass Solution {\npublic:\n int check(vector<int> &s,int i,int n,int sum,vector<vector<int>> &dp)\n {\n if(i==n)\n return(0);\n
shruti_mahajan
NORMAL
2021-06-18T19:40:27.269542+00:00
2021-06-20T09:50:50.930455+00:00
125
false
```\nclass Solution {\npublic:\n int check(vector<int> &s,int i,int n,int sum,vector<vector<int>> &dp)\n {\n if(i==n)\n return(0);\n if(dp[i][n]!=-1)\n return(dp[i][n]);\n return(dp[i][n]=max(sum-s[i]-check(s,i+1,n,sum-s[i],dp),sum-s[n]-check(s,i,n-1,sum-s[n],dp)));\n ...
1
1
[]
2
stone-game-vii
Python | Recursive DP | Min Max | Two Pointer | with Explaination
python-recursive-dp-min-max-two-pointer-bopb4
This is an application of Min/Max algorithm where one of competitor alice, tries to maximize the difference, while other bob tries to minimize it.\n\nSo the DP
PuneethaPai
NORMAL
2021-06-12T15:43:56.315818+00:00
2021-06-13T05:30:23.991994+00:00
187
false
This is an application of Min/Max algorithm where one of competitor `alice`, tries to maximize the difference, while other `bob` tries to minimize it.\n\nSo the DP or recursive solution you write, depending on, which players turn it is, you maximize or minimize the return value.\n\n## Step 1: Identifying sub-problem:\n...
1
0
['Two Pointers', 'Dynamic Programming', 'Recursion', 'Python']
0
stone-game-vii
C++ no prefix sum O(n^2)
c-no-prefix-sum-on2-by-divyanshu41-itpt
We look at turns as both Alice and Bob choosing a stone each with Alice choosing first.\n\nThere are 4 options\n Alice leftmost Bob rightmost -> lr\n Alice left
divyanshu41
NORMAL
2021-06-12T05:29:30.518343+00:00
2021-06-12T05:29:30.518387+00:00
79
false
We look at turns as both Alice and Bob choosing a stone each with Alice choosing first.\n\nThere are 4 options\n* Alice leftmost Bob rightmost -> lr\n* Alice leftmost then Bob leftmost from remaining -> ll\n* Alice rightmost then Bob leftmost -> rl\n* Alice leftmost then Bob rightmost -> lr\n\nWe calculate for all 4 op...
1
1
[]
0
stone-game-vii
Stone Game VII | Dynamic Programming C++ | Beats 99.68% of runtime
stone-game-vii-dynamic-programming-c-bea-wefh
Runtime: 84 ms\nMemory Usage: 14 MB\n\nclass Solution {\npublic:\n int dp[1002][1002] ={0};\n \n \n int stoneGameVII(vector<int>& stones) {\n
simarjot_kaur
NORMAL
2021-06-11T22:56:16.024490+00:00
2021-06-11T23:17:23.517539+00:00
86
false
Runtime: 84 ms\nMemory Usage: 14 MB\n```\nclass Solution {\npublic:\n int dp[1002][1002] ={0};\n \n \n int stoneGameVII(vector<int>& stones) {\n int n = stones.size();\n int total = 0;\n for (int i = n-2; i >=0; i--){\n total = stones[i]+stones[i+1];\n dp[i][i+1] =...
1
0
['C', 'C++']
0