Category: Trie-based system design problem# System Design Questions - OpenAI A collection of commonly asked system design questions from OpenAI interviews.Input: Given input Output: Computed result
codingHardVerified Question#2
2. Count Machines In A Tree
Category: Tree coding problemYou are given a tree-structured network of machines where each node represents a machine. Machines can only communicate with their parent and...Input: String Output: Computed result
codingMediumVerified Question#3
3. Implement cd Command
Category: Algorithm coding problemImplement a simplified version of the Unix cd command. Given a current directory path and a relative destination path, return the final absolute...Input: Given input Output: Computed result
codingMediumVerified Question#4
4. Largest Subgrid
Category: Grid/matrix coding problemYou are given a 2D grid of non-negative integers and a maximum sum constraint. Find the largest size of a square sub-grid such that all...Input: 2D grid Output: Integer
codingHardVerified Question#5
5. Memory Allocator
Category: Linked list coding problem# Memory Allocator Design a memory allocator that manages a contiguous block of memory. Implement malloc and free operations with efficient...Input: Linked list Output: Computed result
codingHardVerified Question#6
6. Toy Language Type Inference
Category: String coding problemImplement a type system for a toy programming language that supports primitives, tuples, and generics. Your task is to represent types and infer...Input: List Output: Computed result
codingMediumVerified Question#7
7. Virus Spread
Category: Grid/matrix coding problemSimulate the spread of a virus through a grid. Each cell can be in one of three states: healthy, infected, or immune. *This is similar to a leetcode...Input: 2D grid Output: Integer
codingMediumVerified Question#8
8. Bot-Enabled Messaging System
Category: String coding problemYou are building a chat system that supports human users and automated bots. Messages are added to a channel log and may trigger bot responses. The...Input: List Output: Computed result
codingHardVerified Question#9
9. Connection Tracker
Category: Algorithm coding problemDesign a social network system that tracks follow relationships between users and preserves a full history through snapshots. The system allows...Input: List Output: Computed result
codingMediumVerified Question#10
10. GPU Credit Ledger
Category: String coding problemYou are designing a system to manage GPU credits. Each credit grant is valid during a specific time window. Events may arrive out of chronological...Input: String Output: Computed result
codingMediumVerified Question#11
11. GPU Credit Manager
Category: String coding problemYou are designing a system to manage GPU credits. Each credit grant is valid during a specific time window. Events may arrive out of chronological...Input: String Output: Computed result
codingHardVerified Question#12
12. In-Memory SQL Engine
Category: String coding problemDesign an in-memory SQL database that supports creating tables, inserting rows with automatic type inference, and querying with filtering and sorting.Input: List Output: Computed result
codingHardVerified Question#13
13. Persistent Key-Value Store
Category: Trie-based coding problemYou are designing a persistent key-value store that serializes its state to a binary storage medium. Native serialization (e.g., JSON, pickle,...Input: Array Output: Computed result
codingHardVerified Question#14
14. Shard Rebalancer
Category: String coding problemYou are implementing a shard management system for a distributed key-value store. Each shard is identified by a string and covers a contiguous range...Input: String Output: Computed result
codingHardVerified Question#15
15. IP Address Iterator
Category: String coding problemEvery device on the public internet is identified by an IPv4 address written in dotted-decimal notation as "A.B.C.D", where each octet is an...Input: String Output: Computed result
codingMediumVerified Question#16
16. Version Support Finder
Category: Binary search coding problemA software company maintains a sorted list of version strings in ascending chronological order. A critical feature was introduced in one version, and...Input: List Output: Computed result
codingMediumVerified Question#17
17. Monster Battle Simulator
Category: String coding problemSimulate a deterministic, turn-based battle between two ordered teams of monsters. Execute the fight step by step and produce a chronological battle...Input: List Output: Computed result
codingMediumVerified Question#18
18. Distributed Tree Messaging
Category: Tree coding problemYou are implementing a message-passing protocol for a distributed system organized as a rooted n-ary tree. Each node represents a machine and...Input: List Output: Printed output
system designSeniormessaging#1
1. [OA] Messaging System Design — Create a Message Queue for OpenAI's Async Processing
To ensure reliable messaging between OpenAI's services and asynchronous job processing, design a class MessageQueue that manages message sending and receiving among services. Class Signature: class MessageQueue: - send_message(service: str, message: str) -> None: Queues a message for the given service. - receive_message(service: str) -> Optional[str]: Retrieves the next message for the specified service, if available. Example 1: Input: mq = MessageQueue() followed by mq.send_message("service1", "Hello World!") and mq.receive_message("service1") Output: "Hello World!" Explanation: The message successfully sent can be retrieved immediately. Example 2: Input: mq.send_message("service2", "Goodbye!") and then mq.receive_message("service1") Output: None Explanation: Since no messages were sent to service1, it returns None. Constraints: - Each service will send up to 10^4 messages per process. - The total number of messages can be up to 10^5.
system designSeniorapi design#2
2. [OA] Object-Oriented Design — Develop a Job Scheduler for OpenAI's Task Management
To streamline task executions across various AI models at OpenAI, we need a JobScheduler that manages scheduling and execution of jobs. Your implementation should handle job queuing and executing based on a predefined delay. Class Signature: class JobScheduler: - add_job(name: str, delay: int) -> None: Adds a job with a name and a delay before execution. - execute_jobs(current_time: int) -> List[str]: Returns a list of job names that are executed at a given current time. Example 1: Input: scheduler = JobScheduler() followed by scheduler.add_job("Task1", 5) and scheduler.execute_jobs(5) Output: ['Task1'] Explanation: The task 'Task1' is executed exactly at time 5. Example 2: Input: scheduler.add_job("Task2", 2) and then scheduler.execute_jobs(3) Output: ['Task2'] Explanation: The task 'Task2' is executed at time 2, even though we checked at time 3. Constraints: - The total number of jobs will not exceed 10^6. - The maximum delay for any job will not exceed 10^9.
codingHarddynamic programming#3
3. [OA] Dynamic Programming — Optimize request batching at OpenAI
In order to improve rate limiting for OpenAI's API, we want to implement a system that optimally combines multiple requests into the fewest batch requests. Given an array of integers representing the request sizes and a maximum batch size, find the minimum number of batches needed to accommodate all requests. Example 1: Input: sizes = [2, 3, 4, 5], max_size = 6 Output: 3 Explanation: The optimal batches would be [2, 3], [4], [5]. Hence 3 batches are needed. Example 2: Input: sizes = [1, 2, 3, 4, 5], max_size = 5 Output: 3 Explanation: The total could be combined as [1, 2], [3, 4], [5] resulting in 3 batches. Constraints: - 1 <= sizes.length <= 1000 - 1 <= sizes[i] <= 1000 - 1 <= max_size <= 1000.
codingHardgraph#4
4. [OA] Graph Traversal — Implement a recommendation system for OpenAI models based on user interactions
OpenAI aims to enhance user experience by suggesting models based on past usage. Your goal is to develop a function that selects model recommendations based on user interaction history represented as a directed graph. Given a Graph object representing user interactions with models, implement a function that returns a list of recommended model IDs the user may like, based on depth-first search (DFS). Example 1: Input: Graph: {1: [2, 3], 2: [4], 3: [4], 4: []}, user_id: 1 Output: [4, 3, 2] Explanation: The user has interacted with model 1, thus traversing through interactions leads to recommendations 4, 3, and 2. Example 2: Input: Graph: {5: [6], 6: [7], 7: [], 8: [7]}, user_id: 5 Output: [7, 6] Explanation: The interactions lead to the models 7 and 6 based on the user’s initial interaction with model 5. Constraints: - The number of models n will be in the range 1 <= n <= 10^4. - The number of interactions will be in the range 0 <= interactions <= 10^4.