Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Maximum Points You Can Obtain from Cards
Bookmark
Brute Force
Sliding Window
Direct Split
Input
Example 1
Example 2
Take All
Edge Case
Custom
cardPoints
=
[1, 2, 3, 4, 5, 6, 1]
,
k
=
3
0
1
2
3
4
5
6
1
2
3
4
5
6
1
call stack (0/3)
empty
path sum =
0
remaining =
0
best =
-
0
1
2
3
4
5
6
1
2
3
4
5
6
1
call stack (0/3)
empty
path sum =
0
remaining =
0
best =
-
0
1
2
3
4
5
6
1
2
3
4
5
6
1
call stack (2/3)
L
1
L
2
take
2
from the left, sum =
3
path sum =
3
remaining =
1
best =
-
0
1
2
3
4
5
6
1
2
3
4
5
6
1
call stack (3/3)
L
1
L
2
L
3
path sum =
6
new best = 6
path sum =
6
remaining =
0
best =
6
0
1
2
3
4
5
6
1
2
3
4
5
6
1
call stack (2/3)
L
1
R
1
take
1
from the right, sum =
2
path sum =
2
remaining =
1
best =
6
0
1
2
3
4
5
6
1
2
3
4
5
6
1
call stack (3/3)
L
1
R
1
R
6
take
6
from the right, sum =
8
path sum =
8
remaining =
0
best =
6
0
1
2
3
4
5
6
1
2
3
4
5
6
1
call stack (1/3)
R
1
take
1
from the right, sum =
1
path sum =
1
remaining =
2
best =
8
0
1
2
3
4
5
6
1
2
3
4
5
6
1
call stack (3/3)
R
1
L
1
L
2
path sum =
4
best stays 8
path sum =
4
remaining =
0
best =
8
0
1
2
3
4
5
6
1
2
3
4
5
6
1
call stack (2/3)
R
1
R
6
take
6
from the right, sum =
7
path sum =
7
remaining =
1
best =
8
0
1
2
3
4
5
6
1
2
3
4
5
6
1
call stack (3/3)
R
1
R
6
L
1
path sum =
8
best stays 8
path sum =
8
remaining =
0
best =
8
0
1
2
3
4
5
6
1
2
3
4
5
6
1
maxScore =
12
algo
master
.
io
Step:
Start: pick k cards from the two ends, trying every choice
0 / 24
Input
Example 1
Example 2
Take All
Edge Case
Custom
cardPoints
=
[1, 2, 3, 4, 5, 6, 1]
,
k
=
3
0 / 24
algo
master
.
io
Step:
Start: pick k cards from the two ends, trying every choice