TechSchool
Home / Interview questions / AI engineering / Cursor

Cursor AI Engineer Interview Questions

Short answers to 17 AI engineering questions asked at Cursor.

Questions and answers (17)

Answers are written in plain English and reviewed for technical accuracy. Each answer states the point first, then the reason.

1. Build a hash tree to organise data in a repository.

A hash tree stores the hash of each file in a leaf node. Each parent node stores the hash of its children. The root hash changes when any file changes. This lets you detect changes by walking the tree.

2. Given a repository snapshot (path → content), build a Merkle tree and write the function returning which files changed between two snapshots without comparing every file's content.

Build a Merkle tree per snapshot and compare the two root hashes first. If the roots match, no file changed. If the roots differ, recurse into child nodes and skip subtrees with equal hashes. This costs O(k log n) work for k changed files.

def changed(a, b, path=""):
    if a.hash == b.hash: return []
    if a.is_leaf: return [path]
    out = []
    for name in a.children:
        out += changed(a.children[name], b.children[name], path + name)
    return out

3. Print the top view of nodes in a binary tree.

Do a level-order traversal and track the horizontal distance of each node. The first node seen at each distance is the top view. Print the collected nodes in order of distance.

from collections import deque
def top_view(root):
    q, seen = deque([(root, 0)]), {}
    while q:
        n, d = q.popleft()
        seen.setdefault(d, n.val)
        if n.left: q.append((n.left, d - 1))
        if n.right: q.append((n.right, d + 1))
    return [seen[d] for d in sorted(seen)]

4. Find duplicate files in a file system.

Hash the content of each file and group files by hash. Files in the same group with the same size are duplicates. Hash comparison avoids reading full content for every pair. A 64-bit hash keeps collisions rare for normal file counts.

import hashlib, os
def dups(root):
    groups = {}
    for d, _, fs in os.walk(root):
        for f in fs:
            p = os.path.join(d, f)
            h = hashlib.sha256(open(p, "rb").read()).hexdigest()
            groups.setdefault(h, []).append(p)
    return [g for g in groups.values() if len(g) > 1]

5. Implement the core of an editor text buffer: efficient insert/delete at arbitrary positions and fast line lookup. What structure do you pick?

Pick a piece table or a gap buffer for the text. A piece table keeps the original text plus an append-only log of edits. It gives O(1) append and fast insert and delete at any position. A line index maps line numbers to offsets for fast line lookup.

6. Serving a custom completion model to millions of DAU: walk me through the inference-cost model and your top three levers.

Cost equals tokens per request times requests per second times cost per token. The top lever is KV cache reuse for shared prefixes such as system prompts. The second lever is batching with paged attention to raise GPU use. The third lever is a smaller model or LoRA adapter for easy traffic.

7. Long context windows keep getting cheaper. Why not drop retrieval and stuff the whole repo into context for every request?

Long context still costs more per request and adds latency. Attention cost grows with the square of the token count. A large repo also pushes past the useful context of most models. Retrieval keeps the prompt small and the answer focused.

8. Design the harness for an agent that makes multi-file changes from a natural-language task. How do you keep it from wrecking a codebase?

Run the agent in a sandbox copy of the repo and apply changes only after tests pass. Give the agent a small tool set with read, search, and patch calls. Require a plan and a diff review before any write. Cap the number of changed files per task.

9. Design an agentic AI system that can autonomously adapt to new tasks.

Build a loop with four parts: a planner, a tool set, a memory store, and a critic. The planner picks the next step, and the critic checks the result against the goal. Add a small library of learned skills so the agent reuses past solutions. Cap the loop at 20 steps to control cost.

10. Design Cursor's tab (next-edit prediction) system: it must feel instant (sub-100 ms perceived latency) for millions of daily users.

Run a small fast model on the local machine and cache its output for the current cursor context. The client sends the context on each keystroke and shows a cached or speculative suggestion at once. A larger server model refines the suggestion in the background. Keep the local model under 100M parameters to hold latency near 30 ms.

11. How would you index a 100k-file monorepo so an AI editor can retrieve relevant context, and keep the index fresh as the user edits?

Build a symbol graph plus a vector index over chunks, and update both from file change events. Parse each file with a real parser to get functions, classes, and imports. Store chunk hashes so you re-embed only changed chunks. A typical edit touches 1 to 3 chunks, so refresh stays under 200 ms.

12. The model is streaming a multi-file edit while the user keeps typing in one of those files. How do you apply the edits without corrupting the buffer?

Track a base version for each file and rebase every streamed edit onto the current buffer. Apply edits as text patches against the base, then map them through the user's changes. If a patch conflicts, drop it and ask the model to regenerate. This keeps the user's keystrokes and never overwrites the buffer.

13. Your agent model outputs an edited version of a 500-line file. Applying it verbatim is slow and error-prone. How do you make “apply” fast and reliable?

Ask the model for a structured patch instead of a full file, then apply it with a fuzzy matcher. A full rewrite costs 500 output lines, and one wrong line breaks the file. A patch of 20 lines is cheaper and easier to verify. Fall back to a full write only when the patch fails to apply.

14. An agent needs to iterate on code (run builds, tests, lints) without disturbing what the user sees in their editor. Architect that.

Give the agent a separate workspace, such as a git worktree or a container, and run builds and tests there. The user's editor keeps its own buffer and never sees the agent's writes. Stream only the final diff back to the editor. A worktree costs one checkout, and a container adds about 2 seconds of start time.

15. How do you evaluate a code-editing model before shipping it? Design the offline and online eval story for tab or agent edits.

Use offline evals on a fixed set of edit tasks and online evals on real accept and reject signals. Offline, measure exact-match and test-pass rates on held-out repos. Online, track accept rate, undo rate, and latency per request. Ship only when offline scores hold and online accept rate does not drop.

16. You have two days in our codebase and no assigned task. What do you build, and how do you spend the time?

I build a small tool that removes one daily friction in the codebase, then measure it. Day one, I read the code, run the tests, and find one slow or manual step. Day two, I ship a fix with tests and a short note. I pick a task I can finish, because a working change teaches more than a plan.

17. Tell me about a time you made short-term sacrifices for long-term gains.

I chose to spend two weeks writing tests and fixing slow code before a demo. The demo came later, but the team shipped fewer bugs after that. The short delay cost us one sprint, and the test suite cut release fixes by about half.

Related lessons
Ai agent intro Ai agent function calling Agent architecture Ai rag Retrieval augmented generation Vector database