The Link Shrinker
A medium Python interview practice problem on DataDriven. Write and execute real python code with instant grading.
- Domain
- Python
- Difficulty
- medium
- Seniority
- L4
Problem
You're building the write side of a URL shortener. Given a `url` and a mutable dict `code_map`, use the first 6 hex characters of the URL's MD5 digest as its short code, save `code_map[code] = url`, and return the code. If that code is already taken by a different URL, take one more hex character until it's free (the visible tests won't force a collision).
Summary
Long addresses have aliases - you give them out, you keep the map.
Practice This Problem
Solve this Python problem with real code execution. DataDriven runs your Python code in a real environment and grades it automatically.