OpenAI logo

OpenAI Interview Questions

59 practice questions for OpenAI technical interviews

OpenAI software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.

Software Engineer Backend Engineer Frontend Engineer Full Stack Engineer Mobile Engineer Data Engineer Data Scientist ML Engineer DevOps Engineer DevOps Engineer Product Manager SRE Security Engineer Engineering Manager Data Analyst UX/UI Designer QA Engineer
17
Coding
1
System Design
coding Hard Verified Question #1

1. Count Machines In A Tree


Category: Tree coding problem
You 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
coding Medium Verified Question #2

2. Implement cd Command


Category: Algorithm coding problem
Implement 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
coding Medium Verified Question #3

3. Largest Subgrid


Category: Grid/matrix coding problem
You 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
coding Hard Verified 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
coding Hard Verified Question #5

5. Toy Language Type Inference


Category: String coding problem
Implement 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
coding Medium Verified Question #6

6. Virus Spread


Category: Grid/matrix coding problem
Simulate 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
coding Medium Verified Question #7

7. Bot-Enabled Messaging System


Category: String coding problem
You 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
coding Hard Verified Question #8

8. Connection Tracker


Category: Algorithm coding problem
Design 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
coding Medium Verified Question #9

9. GPU Credit Ledger


Category: String coding problem
You 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
coding Medium Verified Question #10

10. GPU Credit Manager


Category: String coding problem
You 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
coding Hard Verified Question #11

11. In-Memory SQL Engine


Category: String coding problem
Design 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
coding Hard Verified Question #12

12. Persistent Key-Value Store


Category: Trie-based coding problem
You 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
coding Hard Verified Question #13

13. Shard Rebalancer


Category: String coding problem
You 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
coding Hard Verified Question #14

14. IP Address Iterator


Category: String coding problem
Every 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
coding Medium Verified Question #15

15. Version Support Finder


Category: Binary search coding problem
A 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
coding Medium Verified Question #16

16. Monster Battle Simulator


Category: String coding problem
Simulate 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
coding Medium Verified Question #17

17. Distributed Tree Messaging


Category: Tree coding problem
You 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 design Hard Verified 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
coding Medium dynamic programming #1

1. Dynamic Programming — Maximize the AI Model Performance

Background: OpenAI continuously strives to improve the performance of its machine learning models based on provided data inputs. Efficient optimization algorithms are crucial for predicting outcomes accurately and ensuring models are trained effectively.
Problem statement: Given a list of integers representing the performance scores of an AI system on different datasets, you need to determine the maximum sum of non-adjacent scores possible. This means you cannot select scores that are consecutive.
Function/class signature:
  • def max_non_adjacent_score(scores: List[int]) -> int:

Example 1:
  • Input: [3, 2, 5, 10, 7]

  • Output: 15

  • Explanation: Choose scores 3, 10, and 2 to get 3 + 10 + 2 = 15, skipping the adjacent 2 and 5.

Example 2:
  • Input: [1, 2, 3, 1]

  • Output: 4

  • Explanation: Choose scores 1 and 3 to get 1 + 3 = 4, avoiding the adjacent scores.

Constraints:
  • 0 <= scores.length <= 1000

  • 0 <= scores[i] <= 1000
coding Medium dynamic programming #2

2. Dynamic Programming — Maximum Path Sum in a Grid

Background: OpenAI often deals with large data flows and needs efficient algorithms to compute aggregates over its underlying data. Applications in AI systems and optimization problems can utilize these algorithms effectively.
Problem statement: Given a m x n grid filled with non-negative integers, find a path from the top-left corner to the bottom-right corner, which minimizes the sum of the values along the path. You can only move down or right at any point in time.
Function/class signature:
  • def min_path_sum(grid: List[List[int]]) -> int:

Example 1:
  • Input: [[1,3,1],[1,5,1],[4,2,1]]

  • Output: 7

  • Explanation: The path 1 → 3 → 1 → 2 → 1 minimizes the sum to 7.

Example 2:
  • Input: [[1,2,3],[4,5,6]]

  • Output: 12

  • Explanation: The path 1 → 2 → 3 → 6 minimizes the sum to 12.

Constraints:
  • 1 <= m, n <= 100

  • 0 <= grid[i][j] <= 100
coding Medium dynamic programming #3

3. Dynamic Programming — Subset Sum Problem

Background: OpenAI often deals with optimization problems that can benefit from strategies like the subset-sum problem. It's essential for resource allocation in AI training workflows where budget constraints are significant.
Problem statement: Given a set of n integers and a target integer target, determine if there's a subset of the given integers that adds up to exactly the target value. You should implement a function that efficiently solves this problem using dynamic programming.
Function/class signature:
  • def subset_sum(nums: List[int], target: int) -> bool:

Example 1:
  • Input: nums = [3, 34, 4, 12, 5, 2], target = 9

  • Output: True

  • Explanation: The subset {4, 5} adds up to 9.

Example 2:
  • Input: nums = [1, 2, 3, 7], target = 6

  • Output: True

  • Explanation: The subset {1, 2, 3} adds up to 6.

Constraints:
  • 0 < n <= 20

  • -1000 <= nums[i] <= 1000

  • 0 <= target <= 1000
coding Medium graph #4

4. Graph — Shortest Path in a Multi-Source Scenario

Background: In designing efficient AI systems, OpenAI needs to optimize routes for data points that originate from multiple sources. This is crucial for minimizing response times in API services that rely on complex data paths.
Problem statement: You are given an undirected graph represented as a list of edges, and multiple source nodes. Your task is to find the shortest distance from any of the source nodes to all other nodes in the graph. The distance between two connected nodes is uniformly 1.
Function/class signature:
  • def multi_source_shortest_path(edges: List[Tuple[int, int]], sources: List[int]) -> Dict[int, int]:


Example 1:
Input: edges = [(0, 1), (1, 2), (0, 2), (2, 3)], sources = [0]
Output: {0: 0, 1: 1, 2: 1, 3: 2}
Explanation: The shortest paths from node 0 are as follows: to itself is 0, to 1 is 1, to 2 is 1, and to 3 is 2.
Example 2:
Input: edges = [(0, 1), (1, 2), (2, 3), (3, 4), (4, 1)], sources = [1, 3]
Output: {0: 2, 1: 0, 2: 1, 3: 0, 4: 1}
Explanation: The shortest distances are calculated from both sources 1 and 3.
Constraints:
  • The number of edges (|E|) is between 1 and 10^5.

  • The number of nodes (|V|) is between 1 and 10^5.

  • Each edge connects two different nodes.

  • Nodes are labeled with integers from 0 to V-1.


coding Medium graph #5

5. Graph Traversal — Scheduling Human Labeling Tasks


Background: OpenAI often relies on human labelers to accurately annotate data for machine learning models. It is critical to ensure that labeling tasks are efficiently distributed among available labelers to maintain productivity and prevent overload.
Problem statement: Given a set of labelers, a list of tasks with required time to complete, and models that need this data, create a function that returns a balanced assignment of tasks to each labeler. Every label should have an equitable workload within a specified limit.
Function/class signature:
  • def assign_tasks(labelers: List[str], tasks: List[int], max_load: int) -> Dict[str, List[int]]:


Example 1:
  • Input: labelers = ['Alice', 'Bob', 'Charlie'], tasks = [3, 1, 4, 2, 5], max_load = 5

  • Output: {'Alice': [3, 2], 'Bob': [1, 4], 'Charlie': [5]}

  • Explanation: Each labeler has a total load that does not exceed the max_load of 5.


Example 2:
  • Input: labelers = ['Dave', 'Eve'], tasks = [1, 2, 3], max_load = 3

  • Output: {'Dave': [1, 2], 'Eve': [3]}


Constraints:
  • 1 <= len(labelers) <= 10

  • 1 <= len(tasks) <= 100

  • 0 <= tasks[i] <= 10

  • max_load > 0
coding Medium dynamic programming #6

6. Dynamic Programming — Minimum Cost Path in a 2D Grid

Background: In many machine learning applications at OpenAI, including reinforcement learning and optimization problems, finding efficient pathways is crucial. This problem relates to ensuring optimal resource allocation in grid environments, possibly related to robotics or game simulations.
Problem statement: Given a 2D grid costs where each integer represents the cost to step on that cell, write a function to find the minimum cost to reach the bottom right corner of the grid from the top left corner. You can only move down or right at any point in time.
Function/class signature:
  • def min_cost_path(costs: List[List[int]]) -> int:

Example 1:
  • Input: [[1, 3, 1], [1, 5, 1], [4, 2, 1]]

  • Output: 7

  • Explanation: The path is 1 -> 3 -> 1 -> 1 -> 1, total cost = 7.

Example 2:
  • Input: [[10, 2], [1, 1]]

  • Output: 3

  • Explanation: The path is 10 -> 1 -> 1, total cost = 3.

Constraints:
  • 1 ≤ costs.length, costs[i].length ≤ 100

  • 0 ≤ costs[i][j] ≤ 100
coding Medium dynamic programming #7

7. Dynamic Programming — Longest Increasing Subsequence

Background: OpenAI frequently works with time series data and machine learning models that involve sequential predictions. Identifying patterns, such as trends in data, is crucial for optimizing model performance.
Problem statement: Given an integer array nums, return the length of the longest increasing subsequence. A subsequence is formed by removing elements from the array without changing the order of the remaining elements. This problem is essential for analyzing sequences in large datasets relevant to OpenAI's products.
Function/class signature:
  • def length_of_LIS(nums: List[int]) -> int:

Example 1:
Input: nums = [10,9,2,5,3,7,101,18]
Output: 4
Explanation: The longest increasing subsequence is [2,3,7,101], therefore the length is 4.
Example 2:
Input: nums = [0,1,0,3,2,3]
Output: 4
Explanation: The longest increasing subsequence is [0,1,2,3], therefore the length is 4.
Constraints:
  • 1 <= nums.length <= 2500

  • -10^4 <= nums[i] <= 10^4

coding Hard sliding window #8

8. [OA] Sliding Window — Optimize model inference response times

OpenAI's inference API must handle continuous input streams efficiently, ensuring optimal latency and throughput.
Given an array of integers, find the maximum sum of a subarray of size k.

Function Signature


  • def max_sum_subarray_of_k(arr: List[int], k: int) -> int: Returns the maximum sum of the subarray of size k.


Example 1:


Input: arr = [1, 2, 3, 4, 5], k = 3
Output: 12
Explanation: The maximum sum subarray of size 3 is [3, 4, 5] with a sum of 12.

Example 2:


Input: arr = [2, 3, 4, 1, 5], k = 2
Output: 7
Explanation: The maximum sum is from the subarray [4, 1].

Constraints:


  • 0 < len(arr) <= 1000

  • 1 <= k <= len(arr)
coding Hard dynamic programming #9

9. [OA] Dynamic Programming — Optimize OpenAI's text completion efficiency

OpenAI's text completion models require efficient algorithms to generate responses in real-time while minimizing computational cost.
Given an array of integers representing the tokens in a sequence, you need to calculate the maximum non-adjacent sum of tokens that can be chosen from this array.

Function Signature


  • def max_non_adjacent_sum(tokens: List[int]) -> int: Returns the maximum sum of non-adjacent integers.


Example 1:


Input: [3, 2, 5, 10, 7]
Output: 15
Explanation: The optimal choice is to take tokens 3, 10, and 2 which gives the maximum sum 15 without selecting adjacent values.

Example 2:


Input: [9, 1, 2, 8, 3]
Output: 17
Explanation: The optimal choice is to take tokens 9, 8, and 3.

Constraints:


  • 0 < len(tokens) <= 1000

  • 0 <= tokens[i] <= 1000
system design Hard data structure #10

10. [OA] MedianFinder — Implement a data structure for keeping OpenAI's result metrics

OpenAI often needs to compute the median of predicted metrics in real-time. This requires an efficient data structure to retrieve the median quickly while processing continuous streams of data.

Class Definition


Class MedianFinder should implement the following methods:
  • addNum(num: int) -> None: Adds a number to the data structure.

  • findMedian() -> float: Returns the median of all added numbers.


Example 1:


Input: medianFinder = MedianFinder(); medianFinder.addNum(1); medianFinder.addNum(2); medianFinder.findMedian()
Output: 1.5
Explanation: The median of [1,2] is 1.5

Example 2:


Input: medianFinder.addNum(3); medianFinder.findMedian()
Output: 2
Explanation: The median of [1,2,3] is 2.

Constraints:


  • -10^5 <= num <= 10^5

  • There will be at most 1,000,000 calls to addNum and findMedian.
system design Hard caching #11

11. [OA] LRU Cache — Design an LRU Cache for OpenAI's model predictions

OpenAI needs an efficient caching system to store previously computed model predictions, optimizing resource usage and response time.

Class Definition


Class LRUCache should implement the following methods:
  • get(key: int) -> int: Returns the value of the key if the key exists, otherwise returns -1.

  • put(key: int, value: int) -> None: Updates the value of the key if the key exists existing and moves the key to the front of the cache. Otherwise, it adds the key/value pair to the cache.


Example 1:


Input: cache = LRUCache(2); cache.put(1, 1); cache.put(2, 2); cache.get(1)
Output: 1
Explanation: Returns 1

Example 2:


Input: cache.put(3, 3); cache.get(2)
Output: -1
Explanation: Returns -1 since the cache reached its capacity; LRU (key = 2) was evicted.

Constraints:


  • The capacity of the cache will be between 1 and 1000.

  • All keys will be unique.

Start practicing OpenAI questions

Sign up for free to access walkthroughs, AI-generated questions, and more.

Get Started Free