1. Top 6 Recently Asked Uber System Design Questions
Category: Graph system design problemThis collection covers the most frequently asked system design questions at Uber interviews.Input: Graph (nodes and edges) Output: Computed result
system designHardapi design#1
1. [OA] Twitter Feed — Design a feed system for real-time updates
Uber has a feature to notify drivers of nearby ride requests in real-time. Implement a Twitter-like feed system that delivers updates to users based on user subscriptions to certain categories, allowing users to add, remove, and fetch their feeds.
class Feed:
- def add_category(self, user_id: int, category: str) -> None — Add a category to the user's subscription. - def remove_category(self, user_id: int, category: str) -> None — Remove a category from the user's subscription. - def get_feed(self, user_id: int) -> List[str] — Return the feed of updates for the user.Example 1: Input: feed = Feed(), feed.add_category(1, 'Ride'), feed.add_category(1, 'Promo'), feed.get_feed(1) Output: ['Ride', 'Promo'] Explanation: User 1 subscribes to 'Ride' and 'Promo' categories.Example 2: Input: feed.remove_category(1, 'Promo'), feed.get_feed(1) Output: ['Ride'] Explanation: User 1 unsubscribes from 'Promo'.Constraints:
The maximum number of users is 1 <= user_id <= 10^4.
The maximum number of categories is 1 <= category_count <= 100.
system designHardcaching#2
2. [OA] LRU Cache — Implementing Uber's demand caching system
With millions of users, Uber needs an efficient way to cache frequently requested ride demand data. Implement an LRU (Least Recently Used) cache that allows adding, retrieving, and evicting ride demand based on their usage.
class LRUCache:
- def __init__(self, capacity: int) — Initializes the LRU cache. - def get(self, key: int) -> int — Returns the value of the key if the key exists. - def put(self, key: int, value: int) — Updates the value of the key or adds the key-value pair.Example 1: Input: lru = LRUCache(2), lru.put(1, 1), lru.put(2, 2), lru.get(1) Output: 1 Explanation: Key 1 is present, returning its value.Example 2: Input: lru.put(3, 3), lru.get(2) Output: -1 Explanation: Key 2 was evicted because it was least recently used.Constraints:
The capacity of the cache is 1 <= capacity <= 10^4.
All keys and values are in the range of 1 <= key, value <= 10^5.