The Encode and Decode TinyURL coding problem is a system design-lite task. You need to implement a service that shortens a long URL into a short one (like http://tinyurl.com/4e9iAk) and then redirects the short URL back to the original long one. You must provide two functions: encode(longUrl) and decode(shortUrl).
This is a very popular question at companies like Uber, Amazon, and Salesforce because it mirrors a real-world system architecture problem. It evaluates a candidate's knowledge of hash table interview pattern and their ability to generate unique identifiers. It also opens up discussions about collision handling, database scaling, and the trade-offs between different hashing algorithms.
The problem is typically solved using a Bi-directional Mapping with a Hash Map.
Long URL: https://www.google.com
a1B2c3.{ "a1B2c3": "https://www.google.com" }.http://tinyurl.com/a1B2c3.a1B2c3.https://www.google.com.During the interview, mention the scale. For a real TinyURL service, you'd need to consider how many URLs are generated per second and how long they should be stored. This shows you can think about the problem from a distributed systems perspective.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Design Underground System | Medium | Solve | |
| Design File System | Medium | Solve | |
| Implement Trie (Prefix Tree) | Medium | Solve | |
| Unique Word Abbreviation | Medium | Solve | |
| Time Based Key-Value Store | Medium | Solve |