Anthropic logo

Anthropic Interview Questions

17 practice questions for Anthropic technical interviews

Anthropic 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
9
Coding
1
System Design
coding Hard Verified Question #1

1. OA[CodeSignal] Cloud File Storage System


Category: Graph coding problem

Question Your task is to implement a simple in-memory cloud storage system that maps objects (files) to their metadata (name, size, etc.). You...

Input: Graph (nodes and edges)
Output: Array
coding Hard Verified Question #2

2. OA[CodeSignal] Design Banking System


Category: Graph coding problem

Question Design a banking system that supports account management, transactions, and various financial operations.

Input: Graph (nodes and edges)
Output: Computed result
coding Medium Verified Question #3

3. Convert Stack Samples To A Trace


Category: Interval-based coding problem

Description Sampling profilers capture the call stack at periodic intervals to analyze program performance. However, most trace visualization tools...

Input: List
Output: Computed result
coding Medium Verified Question #4

4. Find Duplicate Files


Category: String coding problem

Description Given a list of file paths in a directory system, find all duplicate files. Two files are considered duplicates if they have identical...

Input: List
Output: Array
coding Hard Verified Question #5

5. Multi Threaded Web Crawler


Category: Graph coding problem

Description Given a URL startUrl and an interface HtmlParser, implement a concurrent web crawler to discover all unique URLs that share the...

Input: Graph (nodes and edges)
Output: Array
coding Hard Verified Question #6

6. OA[CodeSignal] In-Memory Database


Category: Graph coding problem

Description Implement a simplified in-memory database that supports record manipulation with various operations. The system should handle basic...

Input: Graph (nodes and edges)
Output: Array
coding Medium Verified Question #7

7. Service Log Aggregator


Category: Trie-based coding problem
A distributed system emits log entries from multiple services and worker threads. Each log entry is a colon-separated string in the format...
Input: Array
Output: Computed result
coding Hard Verified Question #8

8. Distributed Statistics Engine


Category: String coding problem
A large dataset of integers is distributed across k workers (indexed 0 to k-1). Each worker holds an unsorted, roughly equal slice of the data....
Input: String
Output: Printed output
coding Medium Verified Question #9

9. Longest Match Tokenizer


Category: Array coding problem
You are given a text string text and a dictionary array where each element is in the format "<key>:<id>". Here key is a token string and id...
Input: Array
Output: Computed result
system design Hard Verified Question #10

10. System Design - Inference API


Category: Queue-based system design problem
You need to design a high-concurrency inference API system. This system must handle many requests happening at the same time. You are given an API...
Input: Number(s)
Output: Computed result
coding Medium concurrency #1

1. [Concurrency] — Build a Concurrent Banking System

Background: At Anthropic, designing reliable systems is crucial, especially when dealing with financial applications where multiple users may perform actions simultaneously. This problem relates to ensuring correctness while allowing concurrent access to user accounts.
Problem statement: You are tasked with creating a simplified banking system that allows for the creation of accounts and performing operations such as deposits, withdrawals, and transfers. All operations should be thread-safe to ensure consistency across multiple concurrent accesses. Use a simple in-memory structure to represent accounts.
Function/class signature:
  • class Bank:

  • def __init__(self) -> None:

  • def create_account(self, account_id: str) -> None:

  • def deposit(self, account_id: str, amount: float) -> None:

  • def withdraw(self, account_id: str, amount: float) -> bool:

  • def transfer(self, from_account: str, to_account: str, amount: float) -> bool:

Example 1:
  • Input:

bank = Bank()
bank.create_account('123')
bank.deposit('123', 200.0)
bank.withdraw('123', 50.0)
  • Output: 150.0 (balance after the operations)

  • Explanation: Account '123' is created with a deposit and a withdrawal is done; the remaining balance reflects the operations.

Example 2:
  • Input:

bank.create_account('123')
bank.create_account('456')
bank.deposit('123', 300.0)
bank.transfer('123', '456', 150.0)
  • Output: (True, 150.0) (Transfer was successful, remaining balance for 123 is 150.0)

Constraints:
  • 1 ≤ account_id.length ≤ 100

  • amount ≥ 0

  • The system should handle at least 1000 concurrent transactions.

  • Assume a maximum of 1000 accounts will be created.
coding Medium concurrency #2

2. Concurrency — Implement a Thread-Safe Banking System

Background: Anthropic is focused on developing safe and aligned AI systems, which includes ensuring that concurrent processes like banking have reliable operations. A banking system requires safe handling of multiple transactions to prevent inconsistencies.
Problem statement: You need to design a basic BankingSystem class that allows for concurrent deposits and withdrawals. The system must ensure thread-safety so that operations do not conflict. Implement the following methods in the class:
  • deposit(accountId: int, amount: float) -> None: Increases the balance of the specified account by the given amount.

  • withdraw(accountId: int, amount: float) -> bool: Decreases the balance by the specified amount if sufficient funds are available; returns True if successful, otherwise False.

  • get_balance(accountId: int) -> float: Returns the current balance of the specified account.

Function/class signature:
  • class BankingSystem:

  • def deposit(accountId: int, amount: float) -> None

  • def withdraw(accountId: int, amount: float) -> bool

  • def get_balance(accountId: int) -> float

Example 1:
Input:
bs = BankingSystem()  
bs.deposit(1, 500.0)  
bs.withdraw(1, 200.0)  
bs.get_balance(1)

Output: 300.0
Explanation: The account with ID 1 initially received a deposit of 500, then 200 was withdrawn, leaving a balance of 300.
Example 2:
Input:
bs.withdraw(1, 400.0)

Output: False
Explanation: Insufficient funds for the withdrawal of 400.
Constraints:
  • 1 ≤ accountId ≤ 10000

  • 0 < amount ≤ 10000

  • The operations may occur in concurrent threads.
coding Hard concurrency #3

3. Concurrency and Fault Tolerance — Implement a fault-tolerant concurrent component

Background: Anthropic is focused on developing reliable AI systems that require concurrent operations to handle high-throughput data streams efficiently. Ensuring that these operations are fault-tolerant is crucial for maintaining system integrity and performance, especially in an AI context.
Problem statement: Implement a concurrent class Counter that counts the number of times a specific event occurs while ensuring thread safety. The increment method should increase the counter when an event happens, and the get method should return the current count. If a failure occurs while incrementing, the system should handle this gracefully without losing the count. Use a lock mechanism to ensure thread safety and implement recovery logic.
Function/class signature:
  • def increment(self) -> None:

  • def get(self) -> int:

Example 1:
Input: Event occurs → increment() called
Output: Count = 1 → Explanation: The counter is increased by one.
Example 2:
Input: Event occurs rapidly 100000 times → get() called
Output: Count = 100000 → Explanation: The counter correctly reflects the total increments of events.
Constraints:
  • Maximum concurrent increments: 10,000

  • Ensure failure handling does not result in lost increments

  • Methods must be executed safely in a multi-threaded environment.
coding Medium hash map #4

4. CODING — Implement a banking system to manage accounts


Background: At Anthropic, managing data integrity and transaction processing efficiently is critical for any banking-related application leveraging AI technologies. This problem simulates a rudimentary banking system.
Problem statement: You need to implement a simple banking system that manages accounts having the following operations: create account, deposit, withdraw, and get total transactions. Additionally, there should be a method to return the n accounts with the most total transactions (both deposits and withdrawals).
Function/class signature:
  • class Bank:

  • def create_account(self, account_id: int) -> None:

  • def deposit(self, account_id: int, amount: float) -> None:

  • def withdraw(self, account_id: int, amount: float) -> bool:

  • def get_total_transactions(self, account_id: int) -> float:

  • def get_top_accounts(self, n: int) -> List[int]:


Example 1:
Input:
bank = Bank()  
bank.create_account(1)  
bank.deposit(1, 100)  
bank.withdraw(1, 50)  
bank.create_account(2)  
bank.deposit(2, 200)  
bank.deposit(2, 80)  
bank.get_top_accounts(1)

Output:
[2]
Explanation: Account 2 has the highest total transactions (280).
Example 2:
Input:
bank.create_account(3)  
bank.deposit(3, 150)  
bank.withdraw(3, 30)  
bank.get_top_accounts(2)

Output:
[2, 3]
Explanation: Account 2 has (280) and account 3 has (120) total transactions.
Constraints:
  • 1 <= account_id <= 10^4

  • 0 <= amount <= 10^6

  • All operations are valid according to the problem constraints.

  • 1 <= n <= 100

  • The number of accounts does not exceed 10^4.

coding Medium array #5

5. Max Consecutive Ones — Count maximum consecutive 1s in binary array


Background: At Anthropic, analyzing streaming binary data is crucial for accurate inference in machine learning models. This problem reflects the need to efficiently process data to gather insights for AI alignment and safety.
Problem statement: Given a binary array nums, return the maximum number of consecutive 1s in the array. For example, in the array [1,1,0,1,1,1], the longest consecutive sequence of 1s is 3. Your function should handle large inputs and provide results quickly, as this operation could be part of a larger data analysis framework.
Function/class signature:
  • def findMaxConsecutiveOnes(nums: List[int]) -> int:


Example 1:
Input: findMaxConsecutiveOnes([1,1,0,1,1,1])
Output: 3
Explanation: The longest sequence of 1s is 111.
Example 2:
Input: findMaxConsecutiveOnes([1,0,1,1,0,1])
Output: 2
Explanation: The longest sequence of 1s is 11.
Constraints:
  • 1 <= nums.length <= 10^5

  • nums[i] is either 0 or 1.


coding Medium concurrency #6

6. Concurrency — Implement a fault-tolerant banking system


Background: Anthropic requires a reliable banking system to manage user accounts and transactions, ensuring data integrity and fault tolerance in high-throughput environments.
Problem statement: Implement a simplified banking system where multiple users can create accounts, make scheduled transfers, and view their account balances concurrently. The system must be fault-tolerant and handle potential race conditions when multiple operations occur simultaneously.
Function/class signature:
  • class BankingSystem:

- def create_account(self, account_id: int) -> None:
- def transfer(self, from_account: int, to_account: int, amount: float, schedule_time: datetime) -> bool:
- def get_balance(self, account_id: int) -> float:
Example 1:
  • Input:

create_account(1)
create_account(2)
transfer(1, 2, 100, datetime(2023, 10, 1, 10, 0))
  • Output: True

  • Explanation: User 1 successfully transfers $100 to user 2.


Example 2:
  • Input:

transfer(1, 2, 50, datetime(2023, 10, 1, 10, 0))
  • Output: False

  • Explanation: The transfer fails because account 1 does not have sufficient funds.


Constraints:
  • Account IDs: 1 to 10^5

  • Transfer amount: 1 to 10^4

  • Number of scheduled transfers: up to 10^4 parallel operations

  • Transfer scheduling: can be set at most 1 week ahead.
system design Medium api design #7

7. Design FileStorageSystem — an object-oriented representation of a file storage system


Background: Anthropic requires a scalable file storage system to efficiently manage user files in a way that supports key operations like storing, retrieving, filtering, backing up, and restoring files. This is crucial for data management across various applications.
Requirements:
1. Implement set(file: str, data: bytes) -> None to store a file.
2. Implement get(file: str) -> Optional[bytes] to retrieve file data by name.
3. Implement filter(criteria: Callable[[str], bool]) -> List[str] to return a list of files matching certain conditions.
4. Implement backup(destination: str) -> None to backup all files to a specified location.
5. Implement restore(source: str) -> None to restore files from a backup location.
Class API:
  • set(file: str, data: bytes) -> None: Stores the file file with the content data in bytes.

  • get(file: str) -> Optional[bytes]: Returns the content of the file if it exists, otherwise returns None.

  • filter(criteria: Callable[[str], bool]) -> List[str]: Returns a list of file names that match the given criteria.

  • backup(destination: str) -> None: Backs up the current files to the specified destination.

  • restore(source: str) -> None: Restores files from a backup source.


Example 1:
Input:
  • set('document.txt', b'This is a document.')

  • set('image.png', b'Image data here.')

Output:
  • get('document.txt') returns b'This is a document.'

  • filter(lambda x: x.endswith('.png')) returns ['image.png']

Explanation: The method set is used to store files and get retrieves the content of a specific file. The filter method uses a lambda function to find files with the .png extension.
Example 2:
Input:
  • backup('/backup/location')

  • restore('/backup/location')

Output: No direct output, but files are backed up and restored as needed.
Constraints:
  • Maximum number of files: 1000

  • File name length: up to 255 characters.

  • Data size: up to 1MB per file.


Start practicing Anthropic questions

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

Get Started Free