Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Encode and Decode Strings
Bookmark
Escaping
Length Prefix
Fixed Width
Input
Standard
Special Chars
Single String
Custom
strings
=
[hello, world, , hi]
encode
decode
input
hello
world
""
hi
encode
decode
input
hello
world
""
hi
encode
decode
sb =
9
/20 chars
input
hello
world
""
hi
encoded
5
#
h
e
l
l
o
5
#
0
5
10
15
len(
"world"
) = 5
header =
"5#"
encode
decode
sb =
18
/20 chars
input
hello
world
""
hi
encoded
5
#
h
e
l
l
o
5
#
w
o
r
l
d
0
#
2
#
0
5
10
15
len(
"hi"
) = 2
header =
"2#"
encode
decode
i =
0
result
0
/4
input
hello
world
""
hi
encoded
5
#
h
e
l
l
o
5
#
w
o
r
l
d
0
#
2
#
h
i
0
5
10
15
i
decoded
j = i =
0
scan forward for the '#' separator
encode
decode
i =
0
result
0
/4
input
hello
world
""
hi
encoded
5
#
h
e
l
l
o
5
#
w
o
r
l
d
0
#
2
#
h
i
0
5
10
15
i
decoded
length = int(
"5"
) =
5
encode
decode
i =
7
result
1
/4
input
hello
world
""
hi
encoded
5
#
h
e
l
l
o
5
#
w
o
r
l
d
0
#
2
#
h
i
0
5
10
15
i
decoded
hello
s[8] =
'#'
separator found, stop
encode
decode
i =
14
result
2
/4
input
hello
world
""
hi
encoded
5
#
h
e
l
l
o
5
#
w
o
r
l
d
0
#
2
#
h
i
0
5
10
15
i
decoded
hello
world
j = i =
14
scan forward for the '#' separator
encode
decode
i =
16
result
3
/4
input
hello
world
""
hi
encoded
5
#
h
e
l
l
o
5
#
w
o
r
l
d
0
#
2
#
h
i
0
5
10
15
i
decoded
hello
world
""
""
result +=
""
i = 15 + 1 + 0 =
16
encode
decode
i =
16
result
3
/4
input
hello
world
""
hi
encoded
5
#
h
e
l
l
o
5
#
w
o
r
l
d
0
#
2
#
h
i
0
5
10
15
i
decoded
hello
world
""
s[17] =
'#'
separator found, stop
encode
decode
input
hello
world
""
hi
encoded
5
#
h
e
l
l
o
5
#
w
o
r
l
d
0
#
2
#
h
i
0
5
10
15
decoded
hello
world
""
hi
decode(encode(strs)) == strs
4/4
algo
master
.
io
Step:
Start: pack the list into ONE string by prefixing each string with its length and a '#', then decode it back without any delimiter guessing.
0 / 32
Input
Standard
Special Chars
Single String
Custom
strings
=
[hello, world, , hi]
0 / 32
algo
master
.
io
Step:
Start: pack the list into ONE string by prefixing each string with its length and a '#', then decode it back without any delimiter guessing.