Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
New 21 Game
Bookmark
Input
n=8, k=6, maxPts=4
n=21, k=17, maxPts=10
n=6, k=1, maxPts=10
n=10, k=1 (instant win)
Custom
n
=
8
,
k
=
6
,
maxPts
=
4
n=
8
k=
6
maxPts=
4
1
0
1
2
3
4
5
6
7
8
k = 6 · stop & win →
dp[i] = P(score lands exactly on i); the window sums the scores that can reach i
n=
8
k=
6
maxPts=
4
1
0
1
2
3
4
5
6
7
8
k = 6 · stop & win →
dp[i] = P(score lands exactly on i); the window sums the scores that can reach i
n=
8
k=
6
maxPts=
4
windowSum =
1.0000
window · Σ = 1.000
1
0
.250
1
2
3
4
5
6
7
8
k = 6 · stop & win →
dp[1] =
1.000
/ 4 =
.250
n=
8
k=
6
maxPts=
4
windowSum =
1.5625
window · Σ = 1.563
1
0
.250
1
.313
2
3
4
5
6
7
8
k = 6 · stop & win →
score 2 < k joins window · windowSum +=
0.313
n=
8
k=
6
maxPts=
4
windowSum =
1.9531
window · Σ = 1.953
1
0
.250
1
.313
2
.391
3
4
5
6
7
8
k = 6 · stop & win →
score 3 < k joins window · windowSum +=
0.391
n=
8
k=
6
maxPts=
4
windowSum =
1.4414
window · Σ = 1.441
1
0
.250
1
.313
2
.391
3
.488
4
5
6
7
8
k = 6 · stop & win →
score 0 drops out of window · windowSum -=
1.000
n=
8
k=
6
maxPts=
4
windowSum =
1.5518
window · Σ = 1.552
1
0
.250
1
.313
2
.391
3
.488
4
.360
5
6
7
8
k = 6 · stop & win →
score 1 drops out of window · windowSum -=
0.250
n=
8
k=
6
maxPts=
4
windowSum =
1.2393
window · Σ = 1.239
1
0
.250
1
.313
2
.391
3
.488
4
.360
5
.388
6
7
8
k = 6 · stop & win →
score 2 drops out of window · windowSum -=
0.313
n=
8
k=
6
maxPts=
4
windowSum =
1.2393
window · Σ = 1.239
1
0
.250
1
.313
2
.391
3
.488
4
.360
5
.388
6
.310
7
8
k = 6 · stop & win →
score 7 ≥ k → stopping score,
counts toward the answer
n=
8
k=
6
maxPts=
4
windowSum =
0.8486
window · Σ = 0.849
1
0
.250
1
.313
2
.391
3
.488
4
.360
5
.388
6
.310
7
.212
8
k = 6 · stop & win →
score 8 ≥ k → stopping score,
counts toward the answer
n=
8
k=
6
maxPts=
4
Σ dp[6..8] =
0.90991
1
0
.250
1
.313
2
.391
3
.488
4
.360
5
.388
6
.310
7
.212
8
k = 6 · stop & win →
P(score ≤ 8) = 0.90991
algo
master
.
io
Step:
New 21 Game: draw 1..4 points until score ≥ 6. Find P(final score ≤ 8).
0 / 25
Input
n=8, k=6, maxPts=4
n=21, k=17, maxPts=10
n=6, k=1, maxPts=10
n=10, k=1 (instant win)
Custom
n
=
8
,
k
=
6
,
maxPts
=
4
0 / 25
algo
master
.
io
Step:
New 21 Game: draw 1..4 points until score ≥ 6. Find P(final score ≤ 8).