Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Longest Happy String
Bookmark
Backtracking
Sorting
Max-Heap
Input
Example 1
Example 2
Balanced
Custom
a
=
1
,
b
=
1
,
c
=
7
max-heap by remaining count (top on the left)
a
left:
1
b
left:
1
c
left:
7
greedily take the most plentiful letter, never three in a row
max-heap by remaining count (top on the left)
a
left:
1
b
left:
1
c
left:
7
greedily take the most plentiful letter, never three in a row
len =
3
letters left =
6
max-heap by remaining count (top on the left)
a
left:
0
b
left:
1
c
left:
5
result:
a
c
c
last 2
append
''
→ left
len =
2
letters left =
7
max-heap by remaining count (top on the left)
a
left:
1
b
left:
0
c
left:
6
result:
b
c
last 2
append
''
→ left
len =
1
letters left =
8
max-heap by remaining count (top on the left)
a
left:
1
b
left:
1
c
left:
6
result:
c
try
'c'
len =
4
letters left =
5
max-heap by remaining count (top on the left)
a
left:
0
b
left:
1
c
left:
4
result:
c
a
c
c
last 2
append
''
→ left
len =
3
letters left =
6
max-heap by remaining count (top on the left)
a
left:
1
b
left:
0
c
left:
5
result:
c
b
c
last 2
try
'c'
len =
2
letters left =
7
max-heap by remaining count (top on the left)
a
left:
1
b
left:
1
c
left:
5
result:
c
c
last 2
try
'c'
len =
5
letters left =
4
max-heap by remaining count (top on the left)
a
left:
0
b
left:
1
c
left:
3
result:
c
c
a
c
c
last 2
try
'c'
len =
4
letters left =
5
max-heap by remaining count (top on the left)
a
left:
1
b
left:
0
c
left:
4
result:
c
c
b
c
last 2
try
'c'
len =
8
letters left =
9
max-heap by remaining count (top on the left)
a
left:
1
b
left:
1
c
left:
7
result:
c
c
a
c
c
b
c
c
last 2
result = "ccaccbcc" (len 8)
algo
master
.
io
Step:
Start: a=1, b=1, c=7
0 / 923
Input
Example 1
Example 2
Balanced
Custom
a
=
1
,
b
=
1
,
c
=
7
0 / 923
algo
master
.
io
Step:
Start: a=1, b=1, c=7