A medium Python interview practice problem on DataDriven. Write and execute real python code with instant grading.
- Domain
- Python
- Difficulty
- medium
- Seniority
- L4
Problem
Given a URL string and a mutable dict code_map, generate a 6-character lowercase hex short code from the MD5 hash of the URL (first 6 hex chars), store code_map[code] = url, and return the code. If the code collides with an existing different URL, extend to the next 6 hex chars; keep extending until a unique code (for simplicity tests will not collide).
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.