Skip to content

Practical coding

English · Русский · AI Interview Atlas › Themes

Work-like coding: concurrency, rate limits, retries, evolving specifications, debugging and code review.

On this page: Both tracks (1) · AI Engineering (27)

Both tracks

  • Refactor a small, poorly structured program with passing tests. Explain the first change and how you preserve observable behaviour.
    • Coding · Asked at: OpenAI † · ✍ Answer · Suggest a fix
    • Tests: Whether improvements are incremental and justified by maintainability.
    • A strong answer covers:
      • Pin down observable behaviour first, adding characterisation tests where existing tests assert too little.
      • Make the first change small and mechanical, such as extracting a function, running tests after each step.
      • Justify each step by a maintenance cost it removes, and never mix refactoring with behaviour changes.
    • Read: Working Inside Existing Systems (Palantir Careers) · Refactoring (Martin Fowler)

AI Engineering

  • Implement scaled dot-product attention with a causal mask and tests that would expose attention to future tokens.
    • Coding · Asked at: Amazon †, Anthropic †, Google and Google DeepMind † · ✍ Answer · Suggest a fix
    • Tests: Whether shapes, masking and numerical stability are correct in executable code.
    • A strong answer covers:
      • Check batch, sequence and head dimensions before implementing score multiplication.
      • Use stable softmax after masking disallowed positions.
      • Test small hand-computable cases and ensure changing future inputs cannot change earlier outputs.
    • Read: Attention Is All You Need (Vaswani et al., arXiv)
  • Implement multi-head attention, then modify the implementation so several query heads share each pair of key and value heads.
  • Implement one-token decoding with a KV cache and compare its output with a full-prefix forward pass.
    • Coding · Suggest a fix
    • Tests: Whether positions, cache updates and attention masks remain correct.
    • A strong answer covers:
      • Define the per-layer cache layout and position offsets, including left-padded batches of different lengths.
      • Append the new key and value and attend over the cache: linear work per step, no prefix recompute.
      • Assert logits match a full-prefix forward pass within tolerance, over several steps and padded batches.
    • Read: Optimizing inference (Hugging Face Transformers docs)
  • Write a small BPE trainer and encoder, specifying how merge ties and unseen input symbols are handled.
    • Coding · Suggest a fix
    • Tests: Whether learned merges and encoding behaviour agree.
    • A strong answer covers:
      • Fix the base alphabet, bytes or characters, the pre-tokenisation, and a deterministic tie-break rule.
      • Merge the most frequent adjacent pair repeatedly; encode by applying merges in learned rank order, not longest match.
      • Test decode round-trips, tied counts, empty input and unseen symbols falling back to bytes or an unknown token.
    • Read: Neural Machine Translation of Rare Words with Subword Units (Sennrich et al., arXiv)
  • Implement temperature scaling, top-k filtering and nucleus sampling for a logits vector, including boundary cases.
    • Coding · Asked at: Google and Google DeepMind † · Suggest a fix
    • Tests: Whether probability mass, ties and invalid parameters are handled correctly.
    • A strong answer covers:
      • Define the parameter contract: temperature zero as argmax, valid ranges for k and p, non-finite logits.
      • Use a stable softmax; nucleus keeps the smallest sorted prefix reaching mass p, an O(V log V) sort.
      • Test ties at the cutoff, p near one, k above vocabulary size, and frequencies under a fixed seed.
    • Read: The Curious Case of Neural Text Degeneration (Holtzman et al., arXiv)
  • Build a cache with constant-time lookup and recency updates, then add expiry without breaking eviction semantics.
    • Coding · Asked at: OpenAI † · Suggest a fix
    • Tests: Whether data-structure invariants survive an evolving specification.
    • A strong answer covers:
      • Clarify capacity, whether reads refresh recency, and whether expired entries still count until purged.
      • Use a hash map with a doubly linked list for O(1); one removal path serves expiry and eviction.
      • Test capacity one, updating an existing key, and expiry at exact boundaries with an injected clock.
    • Read: collections: OrderedDict objects (Python Software Foundation) · heapq: Heap queue algorithm (Python Software Foundation)
  • Implement a token-bucket limiter and explain what must change when several workers enforce the same limit.
    • Coding · Asked at: Anthropic †, OpenAI † · ✍ Answer · Suggest a fix
    • Tests: Whether time accounting and concurrent updates preserve the quota.
    • A strong answer covers:
      • Refill from elapsed monotonic time and cap tokens at capacity.
      • Make the check-and-consume operation atomic across competing calls.
      • Test bursts and time boundaries; state the shared-store or partitioning contract for distributed enforcement.
    • Read: Scaling your API with rate limiters (Stripe)
  • Write an asynchronous API batch processor with bounded concurrency, retry jitter and isolated per-item failures.
  • Implement an incremental SSE parser whose data events can contain JSON split across arbitrary network chunks.
    • Coding · Suggest a fix
    • Tests: Whether transport boundaries are kept separate from message boundaries.
    • A strong answer covers:
      • Buffer across chunks, decode UTF-8 incrementally, split lines on CRLF, LF or CR, never rescanning consumed bytes.
      • Accumulate data lines into one event and parse JSON only when a blank line dispatches it.
      • Test a split at every byte offset, including inside multibyte characters, CRLF pairs and the final event.
    • Read: HTML Standard: Server-sent events (WHATWG)
  • Implement overlapping text chunks that preserve semantic units; define what happens when one unit exceeds the target size.
    • Coding · Suggest a fix
    • Tests: Whether ambiguous size and boundary requirements are clarified before coding.
    • A strong answer covers:
      • Clarify the size unit, tokens or characters, what counts as a semantic unit, and how overlap is measured.
      • Pack whole units greedily in one linear pass; split an oversized unit at the next finer boundary.
      • Test oversized units, empty input, overlap not smaller than the target, and lossless reconstruction from offsets.
    • Read: Chunk and vectorize with the Document Layout skill (Microsoft Learn)
  • Implement exact cosine similarity search over embeddings and explain the limits that would require a different production design.
    • Coding · Suggest a fix
    • Tests: Whether a correct baseline is separated from a scalable serving system.
    • A strong answer covers:
      • Normalise vectors once so cosine becomes a dot product; handle zero vectors and dimension mismatches.
      • Score with one matrix product and take top-k by partial selection: O(N·d) per query.
      • Test ties and k above N; once scale forces ANN, keep exact search as the recall baseline.
    • Read: Faiss indexes (Faiss maintainers)
  • Implement a minimal agent runner with validated tool dispatch, error handling and a hard step limit.
    • Coding · ✍ Answer · Suggest a fix
    • Tests: Whether loop state and terminal conditions are explicit in code.
    • A strong answer covers:
      • Hold loop state explicitly: messages, step count, deadline, budget and a termination reason.
      • Validate tool name and arguments against a schema before dispatch; never execute an unregistered tool.
      • Return tool errors to the model as observations while keeping a hard step and time ceiling.
    • Read: Building Effective AI Agents (Anthropic)
  • Implement an in-memory key-value store with begin, commit and abort, stating the transaction semantics you support.
    • Coding · Asked at: OpenAI † · Suggest a fix
    • Tests: Whether rollback and visibility match a precise contract.
    • A strong answer covers:
      • State the contract: whether transactions nest, and whether other clients can see uncommitted writes.
      • Keep a stack of write layers with deletion markers; reads search top-down, commit merges into the parent.
      • Test deleting a key set in the same transaction, nested abort, and commit or abort with none open.
    • Read: Transaction Isolation (PostgreSQL documentation)
  • Write a function that collects a paginated REST result while handling page size, termination and incomplete responses explicitly.
    • Coding · Asked at: Palantir † · Suggest a fix
    • Tests: Whether boundary conditions prevent missing or duplicated records.
    • A strong answer covers:
      • Prefer cursor pagination: with offsets, concurrent inserts and deletes shift pages and cause gaps or duplicates.
      • Terminate on an absent next cursor, not a short page, and guard against a repeated cursor looping forever.
      • Validate each page, retry failures with backoff, dedupe by id; test empty results and exact page-size multiples.
    • Read: AIP-158: Pagination (Google)
  • Plan a product with the interviewer, then build it in about two hours with the AI coding tools of your choice and defend its design, code and path to production.
    • Applied scenario · Asked at: Sierra ✅ · ✍ Answer · Suggest a fix
    • Tests: Whether you scope, build and defend a working product with AI assistance under a time limit.
    • A strong answer covers:
      • Agree the user flow, smallest working slice, time budget and deliberate omissions before delegating bounded pieces.
      • Give each AI task interfaces, relevant context and acceptance checks; inspect diffs and demonstrate behaviour instead of counting generated code.
      • Defend architecture, algorithm assumptions and rejected suggestions; distinguish verified behaviour from production gaps and an unfinished prototype.
    • Read: The AI-native interview (Sierra) · AI Interview Success: An Interviewer's Inside Guide (Canva Engineering Blog)
  • Review and improve a colleague's draft pull request that adds a cross-cutting feature to an unfamiliar codebase, working alongside coding agents.
    • Applied scenario · Asked at: Sierra ✅ · ✍ Answer · Suggest a fix
    • Tests: Whether you judge someone else's change critically instead of accepting what an agent proposes.
    • A strong answer covers:
      • Trace the intended behaviour, entry points, callers and existing invariants before asking the agent to explain or change the diff.
      • Check every affected path, especially authorisation, retries, shared state and migrations; construct a counterexample and a focused regression check.
      • Separate observed defects from hypotheses, verify agent suggestions and explain the approval decision and residual risks; respect the session's AI limits.
    • Read: The AI-native interview (Sierra) · AI Interview Success: An Interviewer's Inside Guide (Canva Engineering Blog) · Demystifying evals for AI agents (Anthropic)
  • Inside a clone of the product's repository, implement a data structure the product actually uses, asking for AI help only on targeted syntax questions.
    • Coding · Asked at: Cursor (Anysphere) 🗣 · ✍ Answer · Suggest a fix
    • Tests: Whether you can read an unfamiliar real codebase and implement a core structure correctly.
    • A strong answer covers:
      • Locate callers, required operations, operation frequency and tests; derive the representation from that contract.
      • State invariants and time/memory costs, then challenge the choice with duplicate, empty and changed-constraint examples.
      • Follow repository conventions and verify behaviour at callers; keep AI help to the targeted syntax questions permitted by this reported session.
    • Read: Working Inside Existing Systems (Palantir Careers) · collections: OrderedDict objects (Python Software Foundation) · Algorithms, fourth edition: Directed Graphs (Robert Sedgewick and Kevin Wayne, Princeton University)
  • Given a real codebase for a working day, decide what to build, ship it, and explain your implementation choices and trade-offs.
    • Applied scenario · Asked at: Cursor (Anysphere) 🗣 · Suggest a fix
    • Tests: Whether you scope your own work, deliver it and defend it without step-by-step direction.
    • A strong answer covers:
      • Explore the codebase first, then pick a change that is useful and finishable within the day.
      • Ship a working core early, then iterate, keeping a running note of decisions and trade-offs.
      • Close with a demonstration, naming its tests and limits and what you would build next.
    • Read: Working Inside Existing Systems (Palantir Careers)
  • In a spreadsheet where cells can reference other cells, detect whether there is a circular reference.
    • Coding · Asked at: Sierra 🗣 · Suggest a fix
    • Tests: Whether you model dependencies as a graph and detect cycles correctly and efficiently.
    • A strong answer covers:
      • Clarify reference forms, ranges and self-references, and whether to report any cycle or every cell in one.
      • Build a dependency graph and run three-colour DFS or Kahn's algorithm in O(cells + references).
      • Test self-loops, long chains against recursion depth, disconnected parts, and rechecking after one formula changes.
    • Read: Algorithms, fourth edition: Directed Graphs (Robert Sedgewick and Kevin Wayne, Princeton University)
  • Build a semantic search over a product catalogue that a chat model can call as a tool.
    • Coding · Asked at: OpenAI † · Suggest a fix
    • Tests: Whether you combine retrieval with a clear, validated tool interface that a model can use reliably.
    • A strong answer covers:
      • Define the tool contract: query, typed filters, a result limit, and compact results with stable product ids.
      • Index product text with embeddings plus keyword matching, and apply filters before ranking.
      • Return actionable errors and explicit empty results; evaluate tool selection and arguments on realistic chat requests.
    • Read: Writing effective tools for AI agents—using AI agents (Anthropic) · Tool use with Claude (Claude Platform Docs)
  • Implement a credit system in which credits carry different expiry rules and usage requirements, and extend it as follow-up requirements arrive.
    • Coding · Asked at: OpenAI † · Suggest a fix
    • Tests: Whether your design absorbs changing business rules without a rewrite.
    • A strong answer covers:
      • Model credits as grants with amount, expiry and conditions, and usage as append-only ledger entries.
      • Isolate the consumption policy, such as soonest expiry first via a heap, so new rules plug in.
      • Test expiry at the exact timestamp, consumption spanning grants, insufficient balance and rebuilding balances from the ledger.
    • Read: heapq: Heap queue algorithm (Python Software Foundation) · Transaction Isolation (PostgreSQL documentation)
  • Find a pair of numbers in an array with a given sum; clarify the conditions, test the code and discuss complexity and edge cases.
  • Optimise the implementation of a given scheduling system, keeping the code clean.
    • Coding · Asked at: Palantir 🗣 · Suggest a fix
    • Tests: Whether you find the real bottleneck and improve it without making the code harder to read.
    • A strong answer covers:
      • Profile on a realistic workload before changing anything, and state the input sizes that matter.
      • Replace the dominant cost with a better structure, such as a heap or interval index, keeping the interface.
      • Keep existing tests passing, add a benchmark, and report complexity and timings before and after.
    • Read: heapq: Heap queue algorithm (Python Software Foundation) · Site Reliability Engineering (Google)
  • Debug a broken API service: trace the logs, find the bottleneck and fix a memory leak.
    • Coding · Asked at: Palantir 🗣 · Suggest a fix
    • Tests: Whether you debug a running service systematically from evidence rather than guesses.
    • A strong answer covers:
      • Reproduce the symptom, then follow one request through the logs to find where time is spent.
      • Test one hypothesis at a time; compare heap snapshots over time to find objects that keep growing.
      • Fix the root cause, such as an unbounded cache or unreleased handles, and prove the fix under load.
    • Read: Site Reliability Engineering (Google) · Working Inside Existing Systems (Palantir Careers)
  • Write SQL queries to answer questions about a dataset, without being able to run them.
    • Coding · Asked at: Palantir 🗣 · Suggest a fix
    • Tests: Whether your data-querying fundamentals hold up without tools to check them.
    • A strong answer covers:
      • Restate each question as the result's grain: what one row represents and which rows qualify.
      • Watch for join fan-out, NULL semantics in filters and aggregates, and WHERE versus HAVING.
      • Trace each query by hand on a few sample rows, including ties, NULLs and empty groups.
    • Read: Table Expressions (PostgreSQL Global Development Group)
  • In an AI-assisted coding session, explain which models you use and why, how you watch the token budget, and how you give the agent its context and task.
    • Applied scenario · ✍ Answer · Suggest a fix
    • Tests: Whether you direct coding agents deliberately rather than accepting their defaults.
    • A strong answer covers:
      • Choose permitted models from task difficulty, observed reliability, latency and budget rather than an assumed universal ranking.
      • Decompose into reviewable steps and supply relevant files, interfaces, invariants, exclusions and a done criterion; treat repository text as untrusted input.
      • Track context, output and retries, preserve verified decisions in a compact handoff, and stop or recover when cost, drift or uncertainty exceeds the agreed limit.
    • Read: Effective context engineering for AI agents (Anthropic) · AI Interview Success: An Interviewer's Inside Guide (Canva Engineering Blog)
  • In an interview where you are expected to use AI tools, how do you stay accountable for code you did not write by hand, and where would you decline what the model produced?
    • Applied scenario · Asked at: Canva ✅ · ✍ Answer · Suggest a fix
    • Tests: Whether ownership and verification survive delegation to a model under time pressure.
    • A strong answer covers:
      • Set the interface, constraints, algorithm assumptions and edge cases yourself before prompting; read the relevant callers.
      • Accept only changes you can explain; reject invented APIs, swallowed errors, weakened tests, excessive scope and instructions embedded in untrusted content.
      • Check the chosen counterexamples independently, explain accepted and rejected suggestions, and disclose what remains unverified under the interview's tool policy.
    • Read: Designing AI resistant technical evaluations (Anthropic) · AI Interview Success: An Interviewer's Inside Guide (Canva Engineering Blog)

← AI system design · AI product strategy and metrics →