Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Encode and Decode TinyURL
Bookmark
Counter
Random Key
Hash-Based
Input
Example 1
Example 2
Custom
operations
=
[["encode","https://example.com"],["encode","https://google.com"],["decode","0"],["decode","1"]]
operations
encode(https://example.com)
encode(https://google.com)
decode(0)
decode(1)
next id
0
operations
encode(https://example.com)
encode(https://google.com)
decode(0)
decode(1)
next id
0
operations
encode(https://example.com)
encode(https://google.com)
decode(0)
decode(1)
encode
next id
1
assign id
long URL
https://example.com
key
0
operations
encode(https://example.com)
encode(https://google.com)
decode(0)
decode(1)
encode
next id
1
assign id
build
long URL
https://example.com
key
0
short URL
http://tinyurl.com/0
hash map (key → URL)
0
→
https://example.com
operations
encode(https://example.com)
encode(https://google.com)
decode(0)
decode(1)
encode
next id
2
assign id
long URL
https://google.com
key
1
hash map (key → URL)
0
→
https://example.com
operations
encode(https://example.com)
encode(https://google.com)
decode(0)
decode(1)
encode
next id
2
assign id
build
long URL
https://google.com
key
1
short URL
http://tinyurl.com/1
hash map (key → URL)
0
→
https://example.com
1
→
https://google.com
operations
encode(https://example.com)
encode(https://google.com)
decode(0)
decode(1)
decode
next id
2
short URL
http://tinyurl.com/0
hash map (key → URL)
0
→
https://example.com
1
→
https://google.com
operations
encode(https://example.com)
encode(https://google.com)
decode(0)
decode(1)
decode
next id
2
extract
short URL
http://tinyurl.com/0
key
0
hash map (key → URL)
0
→
https://example.com
1
→
https://google.com
operations
encode(https://example.com)
encode(https://google.com)
decode(0)
decode(1)
decode
next id
2
short URL
http://tinyurl.com/1
hash map (key → URL)
0
→
https://example.com
1
→
https://google.com
operations
encode(https://example.com)
encode(https://google.com)
decode(0)
decode(1)
decode
next id
2
extract
short URL
http://tinyurl.com/1
key
1
hash map (key → URL)
0
→
https://example.com
1
→
https://google.com
operations
encode(https://example.com)
encode(https://google.com)
decode(0)
decode(1)
next id
2
hash map (key → URL)
0
→
https://example.com
1
→
https://google.com
2 URLs stored
algo
master
.
io
Step:
Counter codec: assign the next integer id and map it to the URL
0 / 17
Input
Example 1
Example 2
Custom
operations
=
[["encode","https://example.com"],["encode","https://google.com"],["decode","0"],["decode","1"]]
0 / 17
algo
master
.
io
Step:
Counter codec: assign the next integer id and map it to the URL