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#2
2. 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#3
3. 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#4
4. 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#5
5. 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#6
6. 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#7
7. 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#8
8. 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#9
9. 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#10
10. 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#11
11. 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#12
12. 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#13
13. 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#14
14. 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#15
15. 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#16
16. 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#17
17. 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 designHardVerified Question#18
18. Top 5 Open AI System Design Questions
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
codingMediumsliding window#1
1. [OA] Sliding Window Technique — Manage a live stream of chatbot messages
OpenAI's chatbot service needs to display a limited number of recent messages without overwhelming users. This exercise involves implementing a sliding window algorithm to fetch and manage the latest messages. Given an array of messages and a number k, write a function that returns the last k messages sent to the chatbot. Function Signature: function getLatestMessages(messages: string[], k: number): string[] Example 1: Input: getLatestMessages(["Hello", "How can I assist you?", "What is OpenAI?", "I love AI!"], 2) Output: ['What is OpenAI?', 'I love AI!'] Explanation: The function returns the last two messages sent to the chatbot.Constraints:
The messages array will have at least one message and at most 10^4 messages.
k will be a positive integer not exceeding the number of messages.
codingHardasync programming#2
2. [OA] Event Loop — Implement a custom Promise for OpenAI's asynchronous data fetching
In a rapidly evolving tech landscape, OpenAI needs robust data fetching capabilities to enhance user experience. This problem requires implementing a custom Promise that includes unique features tailored to OpenAI's needs. Implement a custom Promise class complying with the following methods:
resolve(value: any): void — resolve the promise with the given value.
reject(reason: any): void — reject the promise with the given reason.
then(onResolved: Function, onRejected: Function): Promise — register callbacks to receive either a resolved value or a rejection reason, and return a new promise resolving to the return value of the called callback.
Example 1: Input: new Promise((resolve, reject) => { resolve('Success'); }) Output: 'Success' Explanation: The promise resolves successfully with the value 'Success'.Constraints:
Input values are any valid JavaScript data types.
The promise must maintain a proper chain for chaining multiple then calls.
system designSeniormessaging#3
3. [OA] Design a Notification System for real-time updates
In developing OpenAI's products such as ChatGPT, a notification system for real-time updates on chat or model responses is essential. Design a system that allows publishing notifications and subscribing clients to receive them. Define a class NotificationSystem that manages subscribers and notifications. Implement the following methods:
subscribe(clientId: string, callback: Function): void — register a client with a callback to be notified.
unsubscribe(clientId: string): void — remove a client from the list of subscribers.
notify(message: string): void — send a message to all registered clients.
Example 1: Input: const notificationSystem = new NotificationSystem(); notificationSystem.subscribe('client1', (msg) => console.log(msg)); notificationSystem.notify('New message received!'); Output: New message received! Explanation: Clients registered to receive notifications get the latest updates when notify is called.Constraints:
Client IDs are unique strings.
Each notification should reach all active subscribers.
system designSeniorapi design#4
4. [OA] Design a Client-Side Router for a Single Page Application
OpenAI's applications such as Codex require efficient navigation without reloading entire pages. You are tasked with designing a client-side router for a web application. Define a class Router that manages routes in an SPA. You should implement the following methods:
addRoute(path: string, callback: Function): void — register a route with a specific path and callback function.
navigate(path: string): void — navigate to the specified path and call the associated route's callback.
getCurrentPath(): string — return the current path of the application.
Example 1: Input: const router = new Router(); router.addRoute('/home', () => console.log('Home Page')); router.navigate('/home'); Output: Home Page Explanation: Navigating to '/home' invokes the respective callback.Constraints:
Path strings will always start with '/' and only contain alphanumeric characters and slashes.