Learn
Practice
Newsletter
Resources
Mobile
New
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Logger Rate Limiter
Bookmark
Input
Standard
All Unique
Rapid Same Message
Custom
operations
=
[{"timestamp":1,"message":"foo"},{"timestamp":2,"message":"bar"},{"timestamp":3,"message":"foo"},{"timestamp":8,"message":"bar"},{"timestamp":10,"message":"foo"},{"timestamp":11,"message":"foo"}]
printed =
0
blocked =
0
t
1
2
3
8
10
11
foo
bar
foo
bar
foo
foo
time
0
5
10
15
20
map
empty
printed =
0
blocked =
0
t
1
2
3
8
10
11
foo
bar
foo
bar
foo
foo
time
0
5
10
15
20
map
empty
t =
1
printed =
0
blocked =
0
t
1
2
3
8
10
11
foo
bar
foo
bar
foo
foo
op
time
0
5
10
15
20
map
foo
→
?
"foo"
not in map, no cooldown to check
t =
2
printed =
1
blocked =
0
t
1
2
3
8
10
11
foo
bar
foo
bar
foo
foo
op
time
0
5
10
15
20
map
foo
→
11
bar
→
?
"bar"
not in map, no cooldown to check
t =
2
printed =
2
blocked =
0
t
1
2
3
8
10
11
foo
bar
foo
bar
foo
foo
op
time
0
5
10
15
20
"bar" cooldown
12
map
foo
→
11
bar
→
12
map[
"bar"
] =
2
+ 10 =
12
return true
t =
3
printed =
2
blocked =
1
t
1
2
3
8
10
11
foo
bar
foo
bar
foo
foo
op
time
0
5
10
15
20
"foo" cooldown
11
map
foo
→
11
bar
→
12
t =
3
<
11
still in cooldown
return false
t =
8
printed =
2
blocked =
1
t
1
2
3
8
10
11
foo
bar
foo
bar
foo
foo
op
time
0
5
10
15
20
"bar" cooldown
12
map
foo
→
11
bar
→
12
"bar"
in map
nextAllowed =
12
is t < 12?
t =
10
printed =
2
blocked =
2
t
1
2
3
8
10
11
foo
bar
foo
bar
foo
foo
op
time
0
5
10
15
20
"foo" cooldown
11
map
foo
→
11
bar
→
12
"foo"
in map
nextAllowed =
11
is t < 11?
t =
10
printed =
2
blocked =
3
t
1
2
3
8
10
11
foo
bar
foo
bar
foo
foo
op
time
0
5
10
15
20
"foo" cooldown
11
map
foo
→
11
bar
→
12
t =
10
<
11
still in cooldown
return false
t =
11
printed =
3
blocked =
3
t
1
2
3
8
10
11
foo
bar
foo
bar
foo
foo
op
time
0
5
10
15
20
11
"foo" cooldown
21
map
foo
→
21
bar
→
12
t =
11
>=
11
map[
"foo"
] =
11
+ 10 =
21
return true
t
1
2
3
8
10
11
foo
bar
foo
bar
foo
foo
time
0
5
10
15
20
map
foo
→
21
bar
→
12
printed =
3
blocked =
3
algo
master
.
io
Step:
Start: track each message's nextAllowed time in a hash map. A message may print again only when timestamp >= nextAllowed.
0 / 13
Input
Standard
All Unique
Rapid Same Message
Custom
operations
=
[{"timestamp":1,"message":"foo"},{"timestamp":2,"message":"bar"},{"timestamp":3,"message":"foo"},{"timestamp":8,"message":"bar"},{"timestamp":10,"message":"foo"},{"timestamp":11,"message":"foo"}]
0 / 13
algo
master
.
io
Step:
Start: track each message's nextAllowed time in a hash map. A message may print again only when timestamp >= nextAllowed.