Design a Log Aggregation System

Implement a Log Aggregation System which aggregates logs from various services in a datacenter and provides search APIs. Design the LogAggregator class: LogAggregator(int machines, int services) Initializes the object with machines and services representing the number of machines and services in the datacenter, respectively. void pushLog(int logId, int machineId, int serviceId, String message) Adds a log with id logId notifying that the machine machineId sent a string message while executing...

周日 · 2025-02-23 · 4 分钟 · Yuechen

Design a Rate Limiting System

A Rate Limiting System can allow a maximum of n requests every t seconds, using an implementation similar to the sliding window algorithm. Given two positive integers n and t, and a non-decreasing stream of integers representing the timestamps of requests, implement a data structure that can check if each request is allowed or not. Implement the RateLimiter class: RateLimiter(int n, int t) Initializes the RateLimiter object with an empty...

周六 · 2025-02-22 · 4 分钟 · Yuechen

Design a Todo List

Design a Todo List Where users can add tasks, mark them as complete, or get a list of pending tasks. Users can also add tags to tasks and can filter the tasks by certain tags. Implement the TodoList class: TodoList() Initializes the object. int addTask(int userId, String taskDescription, int dueDate, List<String> tags) Adds a task for the user with the ID userId with a due date equal to dueDate and...

周日 · 2025-02-16 · 4 分钟 · Yuechen

Design Walnut

Design a banking SMS parsing and analytics application (like Walnut) which reads all the text messages received by users and analyzes the following: The income and expenditure of a user. The average income and expenditure of all users. Text messages will be represented as a string, with words separated by ' '. The texts will be analyzed and will be considered valid if it satisfies the following criteria: It contains...

周日 · 2025-01-19 · 4 分钟 · Yuechen

Design Uber

Implement a Cab Booking Application (like Uber) which facilitates: Addition of new cabs to the system. Updating the trips of various customers. Finding the nearest cabs to a location. Design the Uber class: Uber() Initializes the Uber object with 0 cabs and 0 running trips. void addCab(int cabX, int cabY) Adds a cab located at point (cabX, cabY) to the system. Note that multiple cabs can be at the same...

周六 · 2024-12-28 · 5 分钟 · Yuechen

Encode and Decode TinyURL

TinyURL is a URL shortening service where you enter a URL such as https://leetcode.com/problems/design-tinyurl and it returns a short URL such as http://tinyurl.com/4e9iAk. Design a class to encode a URL and decode a tiny URL. There is no restriction on how your encode/decode algorithm should work. You just need to ensure that a URL can be encoded to a tiny URL and the tiny URL can be decoded to the original URL....

周六 · 2024-12-21 · 7 分钟 · Yuechen

Design Twitter

Design a simplified version of Twitter where users can post tweets, follow/unfollow another user, and is able to see the 10 most recent tweets in the user’s news feed. Implement the Twitter class: Twitter() Initializes your twitter object. void postTweet(int userId, int tweetId) Composes a new tweet with ID tweetId by the user userId. Each call to this function will be made with a unique tweetId. List<Integer> getNewsFeed(int userId) Retrieves...

周六 · 2024-12-14 · 4 分钟 · Yuechen

Design a Dating System

Design a simple dating system like Tinder with the following features: Register a user with their gender, age, preferences, and interests. Find matching users according to their preferred gender, preferred age range, and common interests. Implement the Tinder class: Tinder() Initializes the object. void signup(int userId, int gender, int preferredGender, int age, int minPreferredAge, int maxPreferredAge, List<String> interests) Registers a user with the given attributes. List<Integer> getMatches(int userId) Returns the...

周六 · 2024-12-07 · 3 分钟 · Yuechen