Learn
Practice
Newsletter
Resources
F
Toggle theme
0
F
Toggle theme
0
Toggle menu
← Back to All Animations
Random Pick with Weight
Bookmark
Input
Standard
Equal weights
Single weight
Large first
Custom
weights
=
[1, 3, 2, 4]
,
target
=
7
weights
0
1
1
3
2
2
3
4
algo
master
.
io
Step:
Start: Build prefix sum from weights, then binary search for target
0 / 12
Input
Standard
Equal weights
Single weight
Large first
Custom
weights
=
[1, 3, 2, 4]
,
target
=
7
0 / 12
weights
0
1
1
3
2
2
3
4
algo
master
.
io
Step:
Start: Build prefix sum from weights, then binary search for target