OpenAI logo

OpenAI Data Scientist Coding Questions

53 practice questions for OpenAI Data Scientist interviews

OpenAI data scientist interviews test statistical reasoning, ML model design, SQL proficiency, A/B testing methodology, and Python-based algorithm implementation.

All Roles 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
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
coding Hard database #1

1. [OA] Algorithm Complexity — Evaluate model performance metrics in SQL

OpenAI needs efficient ways to calculate performance metrics of its AI models across large datasets.
Problem statement: Given a table model_performance with columns model_id, accuracy, and timestamp, write a SQL query to find the top 5 models by average accuracy over time, ordered from highest to lowest average accuracy.
Example 1:
Input: N/A
Output: "SELECT model_id, AVG(accuracy) AS average_accuracy FROM model_performance GROUP BY model_id ORDER BY average_accuracy DESC LIMIT 5;"
Explanation: This query calculates the average accuracy of each model and retrieves the top 5.
Example 2:
Input: N/A
Output: "SELECT model_id, AVG(accuracy) AS average_accuracy FROM model_performance WHERE timestamp > '2023-01-01' GROUP BY model_id ORDER BY average_accuracy DESC LIMIT 5;"
Explanation: This further restricts to models launched after a specific date.
Constraints:
- model_performance contains at least 1 and at most 100,000 rows.
coding Hard sliding window #2

2. [OA] Sliding Window — Implement a text summarization algorithm for OpenAI's API

The ability to summarize large texts efficiently is crucial for OpenAI's API, allowing users to quickly digest information.
Problem statement: Given an input string text representing a large text body, your task is to implement a function summarize_text(text: str) -> str that uses a sliding window approach to summarize the text by extracting key sentences while maintaining coherence.
- summarize_text returns a str representing the summarized text.
Example 1:
Input: "OpenAI provides a platform for developers to build applications using AI. The company focuses on promoting and advancing artificial intelligence. Their tools are user-friendly and accessible."
Output: "OpenAI provides a platform for developers to build applications using AI. Their tools are user-friendly and accessible."
Explanation: The function extracts 2 key sentences from the input text for the summary.
Example 2:
Input: "Artificial intelligence has numerous applications, including natural language processing and robotics. OpenAI is at the forefront of this technology, constantly innovating products that leverage AI."
Output: "OpenAI is at the forefront of this technology, constantly innovating products that leverage AI."
Constraints:
- text consists of 1 to 10^6 characters.
- The number of sentences in text will not exceed 100.

Related OpenAI Data Scientist interview prep

Start practicing OpenAI questions

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

Get Started Free