Anthropic logo

Anthropic Hard Interview Questions

9 hard-level 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
5
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
Want to practise this one?
Create a free account to open the full question and practise Anthropic questions with AI.
Sign up free
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 Hard Verified Question #3

3. 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 #4

4. 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 Hard Verified Question #5

5. 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
system design Hard Verified Question #6

6. 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 Hard graph #1

1. [AI Enabled Coding] Claude Serving Admission Router


Scenario
Anthropic engineers operating Claude need a deterministic admission router that keeps sessions on the same serving worker when possible without exceeding worker capacity. Implement an in-memory simulation for testing these decisions; then extend it with shared organizational quotas that may overlap through a hierarchy. You may use an AI assistant while coding, but you must explain and test its output.
Part 1 — Capacity-aware sticky routing
  • workers and events are lists of maps with string keys and string values. A worker has worker_id, model, and capacity_tokens; model is a logical serving-pool name such as sonnet.

  • A start event has action, request_id, session_id, model, and tokens. Tokens represent a reservation held until a corresponding finish event, not a billing measurement.

  • Initially, every worker has zero reserved tokens and there are no sticky assignments. Process events in input order.

  • A worker is eligible when its model matches and its current reservation plus the requested tokens is at most capacity_tokens. Equality is allowed.

  • Prefer the previously assigned worker for the pair (session_id, model) if it is eligible. Otherwise, choose the eligible worker with the greatest remaining token capacity before admission; break ties by lexicographically smallest worker_id.

  • An accepted start reserves tokens and updates that session/model pair's sticky assignment. Emit {"request_id": ID, "status": "ACCEPTED", "worker_id": WORKER}. A rejected start changes no state and emits {"request_id": ID, "status": "REJECTED", "reasons": ["NO_CAPACITY"]}.

  • A finish event has only action and request_id. If that request is active, release its reservation and emit status RELEASED with its worker ID. Otherwise, emit {"request_id": ID, "status": "NOOP"}. Finishing a request does not clear its sticky assignment.

  • Implement route_requests(workers: list[dict[str, str]], events: list[dict[str, str]]). The return type is up to you; the examples show its required JSON representation as an ordered list of event results.


Example 1:
Input:
{
  "workers": [
    {"worker_id": "w1", "model": "sonnet", "capacity_tokens": "10"},
    {"worker_id": "w2", "model": "sonnet", "capacity_tokens": "8"}
  ],
  "events": [
    {"action": "start", "request_id": "r1", "session_id": "s1", "model": "sonnet", "tokens": "6"},
    {"action": "start", "request_id": "r2", "session_id": "s1", "model": "sonnet", "tokens": "5"},
    {"action": "start", "request_id": "r3", "session_id": "s2", "model": "sonnet", "tokens": "5"},
    {"action": "finish", "request_id": "r1"},
    {"action": "start", "request_id": "r4", "session_id": "s1", "model": "sonnet", "tokens": "3"}
  ]
}

Output:
[
  {"request_id": "r1", "status": "ACCEPTED", "worker_id": "w1"},
  {"request_id": "r2", "status": "ACCEPTED", "worker_id": "w2"},
  {"request_id": "r3", "status": "REJECTED", "reasons": ["NO_CAPACITY"]},
  {"request_id": "r1", "status": "RELEASED", "worker_id": "w1"},
  {"request_id": "r4", "status": "ACCEPTED", "worker_id": "w2"}
]

Explanation: r1 leaves 4 tokens available on w1. Its session's next request needs 5, so r2 falls back to w2, leaving 3 there. Neither worker can admit r3. After r1 finishes, w1 has 10 available, but r4 still chooses sticky worker w2, reaching exactly its capacity of 8.
Part 2 — Overlapping hierarchical admission policies
Other Claude infrastructure teams now need shared reservation limits across projects and organizations. A worker-only admission decision cannot enforce these overlapping budgets.
  • Add quotas, another list of string-to-string maps. Each record has quota_id, limit_tokens, and parents. parents is a comma-separated list of quota IDs, or the empty string. The graph is a directed acyclic graph; a quota can have multiple parents.

  • Every Part 2 start also has quota_ids, a comma-separated list of directly charged quota IDs, possibly empty. Charge each direct quota and every reachable ancestor exactly once per request, even if there are multiple paths or overlapping direct memberships.

  • For each charged quota q, reject if current_usage[q] + tokens > limit_tokens[q]. Its reason is QUOTA:<quota_id>. Equality is allowed.

  • Evaluate worker capacity and all applicable quotas independently against the state before the event. A rejection must report every violated quota and, if applicable, NO_CAPACITY, with the complete reason list sorted lexicographically. Do not stop at the first violation.

  • Admission is atomic: either reserve on the selected worker and every charged quota, updating stickiness, or change nothing. Finishing an active request releases exactly its original worker and quota reservations.

  • Keep all Part 1 routing and finish behavior. The Part 2 JSON result is an object with results, containing the ordered event results, and quota_usage, mapping every configured quota ID to its final integer usage, including zeros.

  • Implement route_requests_with_quotas(workers: list[dict[str, str]], events: list[dict[str, str]], quotas: list[dict[str, str]]). Discuss how the return type changes before implementing it. Structure admission policies so future policy types can be added without rewriting the routing loop; additional quota nodes and parent edges must remain data-driven.


Example 2:
Input:
{
  "workers": [
    {"worker_id": "w1", "model": "sonnet", "capacity_tokens": "10"},
    {"worker_id": "w2", "model": "sonnet", "capacity_tokens": "8"}
  ],
  "quotas": [
    {"quota_id": "org", "limit_tokens": "12", "parents": ""},
    {"quota_id": "team", "limit_tokens": "8", "parents": "org"},
    {"quota_id": "project", "limit_tokens": "7", "parents": "team,org"}
  ],
  "events": [
    {"action": "start", "request_id": "a", "session_id": "s1", "model": "sonnet", "tokens": "6", "quota_ids": "project,team"},
    {"action": "start", "request_id": "b", "session_id": "s2", "model": "sonnet", "tokens": "3", "quota_ids": "team"},
    {"action": "finish", "request_id": "a"},
    {"action": "start", "request_id": "c", "session_id": "s2", "model": "sonnet", "tokens": "7", "quota_ids": "project"}
  ]
}

Output:
{
  "results": [
    {"request_id": "a", "status": "ACCEPTED", "worker_id": "w1"},
    {"request_id": "b", "status": "REJECTED", "reasons": ["QUOTA:team"]},
    {"request_id": "a", "status": "RELEASED", "worker_id": "w1"},
    {"request_id": "c", "status": "ACCEPTED", "worker_id": "w1"}
  ],
  "quota_usage": {"org": 7, "project": 7, "team": 7}
}

Explanation: a charges project, team, and org once each, giving usages of 6, not 12 or 18. For b, a worker is available, but team usage would be 6 + 3 = 9 > 8; organization usage would be 9 <= 12, and project is not charged. Rejection leaves every usage at 6. Finishing a resets all three to zero; c then reserves 7, satisfying project 7 <= 7, team 7 <= 8, and organization 7 <= 12.
Example 3:
Input:
{
  "workers": [
    {"worker_id": "w1", "model": "sonnet", "capacity_tokens": "10"},
    {"worker_id": "w2", "model": "sonnet", "capacity_tokens": "8"}
  ],
  "quotas": [
    {"quota_id": "org", "limit_tokens": "10", "parents": ""},
    {"quota_id": "team", "limit_tokens": "6", "parents": "org"},
    {"quota_id": "project", "limit_tokens": "6", "parents": "team,org"}
  ],
  "events": [
    {"action": "start", "request_id": "x", "session_id": "s1", "model": "sonnet", "tokens": "6", "quota_ids": "project"},
    {"action": "start", "request_id": "y", "session_id": "s2", "model": "sonnet", "tokens": "9", "quota_ids": "project"},
    {"action": "finish", "request_id": "y"},
    {"action": "finish", "request_id": "x"},
    {"action": "start", "request_id": "z", "session_id": "s1", "model": "sonnet", "tokens": "6", "quota_ids": "team,project"}
  ]
}

Output:
{
  "results": [
    {"request_id": "x", "status": "ACCEPTED", "worker_id": "w1"},
    {"request_id": "y", "status": "REJECTED", "reasons": ["NO_CAPACITY", "QUOTA:org", "QUOTA:project", "QUOTA:team"]},
    {"request_id": "y", "status": "NOOP"},
    {"request_id": "x", "status": "RELEASED", "worker_id": "w1"},
    {"request_id": "z", "status": "ACCEPTED", "worker_id": "w1"}
  ],
  "quota_usage": {"org": 6, "project": 6, "team": 6}
}

Explanation: After x, workers have 4 and 8 tokens available and every quota has usage 6. Request y needs 9, so neither worker fits; each quota would reach 6 + 9 = 15, exceeding limits 10, 6, and 6. All four reasons must appear, and finishing rejected request y is a no-op. Finishing x releases 6 everywhere. Request z charges each node only once despite overlapping memberships, returning all three usages to exactly 6.
Notes:
  • Assume at most 100,000 events, 2,000 workers, and 500 quota nodes. Token reservations are integers from 1 through 10^9; capacities and quota limits are integers from 0 through 10^12. Explain your complexity rather than assuming worker and quota counts are constants.

  • Inputs are well-formed: worker and quota IDs are unique, every start has a globally unique request ID, referenced quota IDs exist, and quota parents form a DAG. IDs contain no commas or whitespace; finish events may reference any request ID.

  • Each function call starts with empty runtime state. Events are sequential, reservations never expire automatically, and the supplied worker and quota configurations do not change during a call.
Want to practise this one?
Create a free account to open the full question and practise Anthropic questions with AI.
Sign up free
coding Hard concurrency #2

2. 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.
system design Hard concurrency #3

3. Design StackTraceReconstructor — reconstruct nested function events from sampled call stacks


Background


Engineers investigating latency in Claude-serving infrastructure need to turn periodic stack samples into timelines that can be inspected by a profiler. Design an in-memory component for that workflow, adapting the stack-trace problem reported in Anthropic interviews. This is a practice design, not a claim about Anthropic's internal profiling implementation.

Requirements


1. Maintain independent state for each thread. A sample contains an integer timestamp and a stack of function names ordered outermost to innermost. The first sample registers the thread; its stack is compared with an empty stack. Subsequent sample timestamps for that thread must be strictly increasing, even when its stack is unchanged or empty. Timestamps across different threads need not be ordered.
2. Reconstruct events using the longest common prefix of the previous and current stacks. Emit end events for the old suffix, innermost first, followed by start events for the new suffix, outermost first. All events use the new sample's timestamp. A frame's depth is its zero-based position in its stack; repeated function names represent distinct recursive frames. Matching prefix frames are assumed to remain active: do not infer unobserved calls between samples.
3. finish(thread_id, timestamp) closes the thread by ending every remaining frame, innermost first. Its timestamp must be at least the thread's latest sample timestamp. Finishing an already finished thread returns false without emitting events or checking the timestamp. Finishing an unknown thread raises ValueError; adding a sample to a finished thread also raises ValueError.
4. Buffer events until drain_events() returns and removes all buffered events. Each event is an object with exactly thread_id, timestamp, kind, function, and depth. Preserve method-call order, not global timestamp order; within a call, preserve the nesting order defined above. A second drain without intervening events returns an empty list. Copy input stacks so later caller mutations cannot change stored state.
5. Make every public operation thread-safe and atomic. Concurrent calls may take effect in any lock-acquisition order, but their events must not interleave. A rejected operation must leave thread state and buffered events unchanged. Keep finished-thread identities so they cannot be reused.

Class API


  • StackTraceReconstructor() — create an empty reconstructor.

  • add_sample(thread_id: str, timestamp: int, stack: list[str]) -> None — register or update a thread and append inferred events; raise ValueError for a finished thread or a non-increasing timestamp.

  • finish(thread_id: str, timestamp: int) -> bool — return true when an active thread is closed, or false if already closed; raise ValueError for an unknown thread or a timestamp earlier than its latest sample.

  • drain_events() -> list[dict[str, str | int]] — atomically return all pending events and clear the buffer.


Example 1


Input sequence:
[
  {"method":"add_sample","args":["worker-1",10,["serve","decode"]]},
  {"method":"add_sample","args":["worker-1",14,["serve","sample"]]},
  {"method":"finish","args":["worker-1",20]},
  {"method":"drain_events","args":[]}
]

Output, one result per call:
[
  null,
  null,
  true,
  [
    {"thread_id":"worker-1","timestamp":10,"kind":"start","function":"serve","depth":0},
    {"thread_id":"worker-1","timestamp":10,"kind":"start","function":"decode","depth":1},
    {"thread_id":"worker-1","timestamp":14,"kind":"end","function":"decode","depth":1},
    {"thread_id":"worker-1","timestamp":14,"kind":"start","function":"sample","depth":1},
    {"thread_id":"worker-1","timestamp":20,"kind":"end","function":"sample","depth":1},
    {"thread_id":"worker-1","timestamp":20,"kind":"end","function":"serve","depth":0}
  ]
]

Explanation: At timestamp 14 the shared prefix is ["serve"], so only decode ends and sample starts. Finishing ends the two remaining frames in reverse depth order.

Example 2


Input sequence:
[
  {"method":"add_sample","args":["A",5,["walk","walk"]]},
  {"method":"add_sample","args":["B",2,[]]},
  {"method":"add_sample","args":["A",6,["walk"]]},
  {"method":"add_sample","args":["B",3,["serve"]]},
  {"method":"finish","args":["A",6]},
  {"method":"finish","args":["A",0]},
  {"method":"drain_events","args":[]},
  {"method":"drain_events","args":[]}
]

Output, one result per call:
[
  null,
  null,
  null,
  null,
  true,
  false,
  [
    {"thread_id":"A","timestamp":5,"kind":"start","function":"walk","depth":0},
    {"thread_id":"A","timestamp":5,"kind":"start","function":"walk","depth":1},
    {"thread_id":"A","timestamp":6,"kind":"end","function":"walk","depth":1},
    {"thread_id":"B","timestamp":3,"kind":"start","function":"serve","depth":0},
    {"thread_id":"A","timestamp":6,"kind":"end","function":"walk","depth":0}
  ],
  []
]

Explanation: Recursive frames are distinguished by depth. Thread B's empty first sample registers it without creating events. Its timestamp-3 event remains after A's timestamp-6 event because calls, rather than timestamps, define buffer order. Repeating finish is a no-op even with an earlier timestamp.

Constraints


  • At most 10,000 distinct thread IDs and 100,000 total sample/finish calls; each stack has at most 1,000 frames.

  • Timestamps are integers in [0, 10^12]; thread IDs and function names are nonempty strings of at most 128 characters. Types and these bounds are guaranteed by callers.

  • At most 1,000,000 events are pending between drains. There are at most 32 concurrent callers, and callers must not mutate an input stack while its call is executing.

  • Use only in-memory state and standard-library facilities; persistence, actual stack sampling, and global timestamp sorting are out of scope.

Start practicing Anthropic questions

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

Get Started Free