[ OK ] 8 — full content available
[ INFO ] category: Coding difficulty: medium freq: high first seen: 2026-01-05
[MEDIUM][CODING][HIGH]String ManipulationCompressionParsing
$ cat problem.md
URL Shortener Service
Design a URL shortening service similar to TinyURL. The service should support two operations:
encode(longUrl):
- Convert a long URL into a shortened URL
- The same long URL should always return the same short URL
- Each unique URL should get a unique short code
decode(shortUrl):
- Convert a shortened URL back to the original long URL
- Return empty string if the short URL doesn't exist
Requirements:
- Short URLs should be deterministic (same input = same output)
- Must handle duplicate encode requests (return existing short URL)
- Must handle non-existent decode requests gracefully
Example:
encode("https://leetcode.com") → "http://tiny/0" encode("https://example.com") → "http://tiny/1" decode("http://tiny/0") → "https://leetcode.com"