Designing a URL shortener is a very common beginner system design interview question. We focus on the read path โ the redirect โ being as fast as physically possible, because reads outnumber writes by ~100:1.
1. Users submit a long URL and receive a shortened version.
2. Users access the original URL via the short link.
3. Optional: custom alias. 4. Optional: expiration date.
Redirect < 100ms ยท 99.99% availability ยท 1B URLs / 100M DAU ยท uniqueness of short codes ยท durable mappings.
# Given a sorted array of integers nums, determine if there # exists a pair of numbers that sum to a given target. # nums=[1,3,4,6,8,10,13], target=13 -> True (3 + 10) # nums=[1,3,4,6,8,10,13], target=6 -> False def two_sum_exists(nums, target): seen = set() for num in nums: if target - num in seen: return True seen.add(num) return False