/Interview

AI interview rounds · Lesson 2 of 8 · 25 min

The AI-enabled coding round

Study with AI

Part 1Basics

You get a problem, an editor and an AI chat. You might expect the test to be easy now. Canva reports the opposite: candidates with little AI experience often struggled, because they lacked the judgment to guide it or to spot its bad suggestions.

So the round tests you as the engineer in charge. The assistant is a fast junior: it types quickly, sounds certain, and is sometimes wrong. You decide the plan, give it small jobs, read what comes back, and prove that it works.

One workflow appears in almost every guide: plan, ask for a small piece, review it, run it, then say what you learned. Repeat.

Words you need

Spec prompt
A request with context, the exact interface, the constraints, and how you'll check it. Far better than 'write the function'.
Happy path
The normal case where nothing goes wrong. AI drafts usually handle it, and interviewers look past it.
Tiered data
Test inputs that grow from small to huge, each exposing a new weakness. Reported as part of Meta's format.

A worked example

Our practice problem is a log file. Each line looks like 1714000000|ERROR|payments|timeout. Stage one: fix a parser you inherit. Stage two: report the top services by error count. Stage three: make it work on a huge file.

Meera fixes stage one by hand, since it's a small change. For stage two she writes a spec prompt, and the assistant returns a clean function that passes her first test. She doesn't stop there. She reads it, spots a plain object used as a map, and asks: what if a service is called 'constructor'? The test she writes for it fails. That moment is what the round is looking for.

Part 2The question

How do you use an assistant in a live round so that it counts in your favour?

By the end of this lesson, you should be able to:

  • Run the plan, prompt, review, run loop
  • Write a spec prompt
  • Find the bugs AI drafts commonly contain
  • Explain every line you keep

Part 3In detail

Step by step

  1. Spend the first minutes without AI. Read the problem, ask questions, and write down what must be true when you're finished.
  2. State your plan out loud. Name the pieces and the data structures. You lead, and the AI follows.
  3. Ask for one small piece. One or two functions, with a clear interface. Large outputs can't be reviewed in a live round.
  4. Read before you accept. Check the boundaries, empty input, ties, and what it assumed.
  5. Run it and write a test it might fail. Then say what you learned.
  6. Rerun everything after each fix. Fixing one test while breaking another is a common way to fail.
  7. Be ready to work without it. Reports say the assistant may be less helpful than in practice, and some stages may not allow it.

What to give the AI, and what to keep

Good jobs for it: boilerplate, test scaffolding, a function with a clear interface, explaining an unfamiliar API, and suggesting edge cases you can then check.

Jobs to keep: understanding the problem, choosing the design, deciding what's correct, and small fixes you can make faster than you can describe them.

When it's wrong, say so

Catching a bug in AI code isn't embarrassing. It's the highest-value moment in the round. Say what you noticed, how you'll prove it, and fix it. Then move on without fuss.

Prompts to copy

A spec prompt, for a live round

Fill it in fast. It takes under a minute, and it saves the review time.

Write one TypeScript function.
Signature: topErrors(entries: Iterable<LogEntry>, k: number): [string, number][]
It returns the k services with the most ERROR entries, highest first, breaking ties by name.
Constraints: don't change LogEntry. No libraries. Handle k = 0 and empty input.
Don't write tests or explain it. I'll review it myself.

Find what I missed

Use the AI against its own code, then verify what it says.

Here's a function and its tests:
[code]
List 5 inputs likely to break it that the tests don't cover. For each, say what you expect to happen. Don't change the code.

The code, explained

This is real code, and our tests run it, including the buggy versions, to prove the bugs are real.

Stage 1: the code you inherit

A parser with a real bug. Read it before you scroll on.

LogTriage.tsTypeScript
1/** Stage 1, the code you inherit. A message may contain "|", and this drops everything after it. */2export function parseLineBuggy(line: string): LogEntry | null {3  const [at, level, service, message] = line.split("|");4  if (!message) return null;5  return { at: Number(at), level, service, message };6}
6 linesUTF-8TypeScript
line.split("|")
Splits on every separator, but the message itself may contain one.
const [at, level, service, message]
Takes four parts and silently drops the rest. No error appears, and the data is just wrong.
Number(at)
A bad timestamp becomes NaN, which sails through.

Tested by npm run test:modules.

Stage 1: the fix

Fixed by hand. A bug this small is quicker to fix than to explain to an assistant.

LogTriage.tsTypeScript
1/** Split only the first three separators, and reject a timestamp that isn't a number. */2export function parseLine(line: string): LogEntry | null {3  const parts = line.split("|");4  if (parts.length < 4) return null;5  const at = Number(parts[0]);6  if (!Number.isFinite(at)) return null;7  return { at, level: parts[1], service: parts[2], message: parts.slice(3).join("|") };8}
8 linesUTF-8TypeScript
parts.slice(3).join("|")
Puts the message back together, separators included.
Number.isFinite(at)
Rejects NaN and Infinity, so a bad line can't poison later sorting.

Tested by npm run test:modules.

Stage 2: the assistant's first draft

It's short, clean and passes the obvious test. It also has two bugs. Our tests prove both.

LogTriage.tsTypeScript
1/** Stage 2, what an assistant writes first. It looks right and passes a happy-path test. */2export function topErrorsDraft(entries: LogEntry[], k: number): [string, number][] {3  const counts: Record<string, number> = {};4  for (const e of entries) {5    if (e.level === "ERROR") counts[e.service] = (counts[e.service] || 0) + 1;6  }7  return Object.entries(counts).sort((a, b) => b[1] - a[1]).slice(0, k);8}
8 linesUTF-8TypeScript
const counts: Record<string, number> = {}
A plain object inherits keys. A service named 'constructor' finds a function there, so the count becomes a string.
counts[e.service] || 0
This is where it happens: the inherited function is truthy, so it never falls back to 0.
sort((a, b) => b[1] - a[1])
Equal counts keep input order, so the same data in a different order gives a different answer.

Tested by npm run test:modules.

Stage 2: after your review

A small change, and the kind interviewers want to see you catch.

LogTriage.tsTypeScript
1/** After review: a Map has no inherited keys, and the tie-break makes the output repeatable. */2const byCountThenName = (a: [string, number], b: [string, number]) => b[1] - a[1] || a[0].localeCompare(b[0]);3 4export function topErrors(entries: Iterable<LogEntry>, k: number): [string, number][] {5  const counts = new Map<string, number>();6  for (const e of entries) {7    if (e.level === "ERROR") counts.set(e.service, (counts.get(e.service) ?? 0) + 1);8  }9  return [...counts].sort(byCountThenName).slice(0, k);10}
10 linesUTF-8TypeScript
new Map<string, number>()
A Map starts empty, with no inherited keys.
b[1] - a[1] || a[0].localeCompare(b[0])
A tie-break makes the output repeatable, which also makes it testable.
entries: Iterable<LogEntry>
Accepts a list or a stream, which sets up stage 3.

Tested by npm run test:modules.

Stage 3: when the big file arrives

With m services, sorting costs O(m log m). A heap of size k costs O(m log k), which matters when m is large and k is small.

LogTriage.tsTypeScript
1/** Stage 3, for millions of lines: read a stream, and keep only k candidates in a min-heap. */2export function topErrorsFast(lines: Iterable<string>, k: number): [string, number][] {3  const counts = new Map<string, number>();4  for (const line of lines) {5    const e = parseLine(line);6    if (e?.level === "ERROR") counts.set(e.service, (counts.get(e.service) ?? 0) + 1);7  }8  if (k <= 0) return [];9  const heap: [string, number][] = [];10  // The root is the entry that ranks last, so it is the one to replace.11  const ranksLater = (a: [string, number], b: [string, number]) => byCountThenName(a, b) > 0;12  const up = (start: number) => {13    let i = start;14    while (i > 0) {15      const p = (i - 1) >> 1;16      if (!ranksLater(heap[i], heap[p])) break;17      [heap[i], heap[p]] = [heap[p], heap[i]];18      i = p;19    }20  };21  const down = () => {22    let i = 0;23    for (;;) {24      let top = i;25      for (const c of [2 * i + 1, 2 * i + 2]) if (c < heap.length && ranksLater(heap[c], heap[top])) top = c;26      if (top === i) return;27      [heap[i], heap[top]] = [heap[top], heap[i]];28      i = top;29    }30  };31  for (const item of counts) {32    if (heap.length < k) {33      heap.push(item);34      up(heap.length - 1);35    } else if (ranksLater(heap[0], item)) {36      heap[0] = item;37      down();38    }39  }40  return heap.sort(byCountThenName);41}
41 linesUTF-8TypeScript
lines: Iterable<string>
Reads one line at a time, so a huge file never has to fit in memory. Only the counts do.
ranksLater
Puts the worst of the current top k at the root, ready to be replaced.
ranksLater(heap[0], item)
A new item enters only if it beats the worst one kept.
heap.sort(byCountThenName)
A heap isn't sorted, so the k winners get a final sort.

Tested by npm run test:modules.

What can go wrong

Asking it to solve everything
You get a large answer that you can't review, and an interviewer watching you read it for the first time.
Going silent while it writes
Use the wait: review the last piece, or say what you'll do next.
A fix that special-cases the test
A model may make a failing test pass by hard-coding it. Read the fix, not just the green tick.
Polishing too early
Naming and tiny optimisations can wait until the core works.

Part 4Questions and answers

Answer out loud first, then open each one.

Why was topErrorsDraft wrong even though it passed?
A plain object inherits keys like 'constructor', which corrupts that count, and ties depend on input order. The happy-path test touches neither.
When is it faster not to use the AI?
When a fix is small and you know it. A one-line change takes longer to explain than to make, and it shows you understand the code.
What's the cost of the heap version?
O(m log k) for m services and top k, compared with O(m log m) for a full sort. The counts still take memory proportional to m, whichever you use.
The AI suggests a library you've never used. What do you do?
Ask what it does, check whether it's allowed and needed, and prefer the option you can explain. You're answerable for what you keep.
How much should you talk?
At useful moments: your plan, after test runs, when you catch something, and at the end. Don't narrate each keystroke, and don't go quiet for long.

Part 5Going further

Drill: Do the log problem, timed (60 min)

  1. Close this page. Set a 60-minute timer, and use any assistant.
  2. Stage 1: fix the parser so a message may contain '|'.
  3. Stage 2: top k services by error count, with a repeatable order.
  4. Stage 3: make it work on a stream of 10 million lines.
  5. Compare your work with the code here, then log your misses.

Score yourself

Tick a line only if you did it without prompting.

0 of 7 Repeat the drill, and aim for the lines you missed.

Keep the fundamentals fresh with the critical basics.

Who says so

Checked in November 2026. Vendors and individuals often report what candidates told them, so treat their details as reports.

Next: when the code isn't yours or the AI's. You're handed a file you've never seen.

Next: Reading unknown code →

← The new interview map

AI Engineer · AI interview rounds