The AI-enabled coding round

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

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.

  • 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.

Steps:

  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.

Prompt, A spec prompt, for a live round:

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.

Prompt, Find what I missed:

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.

Code, Stage 1: the code you inherit. A parser with a real bug. Read it before you scroll on.

/** Stage 1, the code you inherit. A message may contain "|", and this drops everything after it. */
export function parseLineBuggy(line: string): LogEntry | null {
  const [at, level, service, message] = line.split("|");
  if (!message) return null;
  return { at: Number(at), level, service, message };
}
  • 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.

Code, Stage 1: the fix. Fixed by hand. A bug this small is quicker to fix than to explain to an assistant.

/** Split only the first three separators, and reject a timestamp that isn't a number. */
export function parseLine(line: string): LogEntry | null {
  const parts = line.split("|");
  if (parts.length < 4) return null;
  const at = Number(parts[0]);
  if (!Number.isFinite(at)) return null;
  return { at, level: parts[1], service: parts[2], message: parts.slice(3).join("|") };
}
  • 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.

Code, 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.

/** Stage 2, what an assistant writes first. It looks right and passes a happy-path test. */
export function topErrorsDraft(entries: LogEntry[], k: number): [string, number][] {
  const counts: Record<string, number> = {};
  for (const e of entries) {
    if (e.level === "ERROR") counts[e.service] = (counts[e.service] || 0) + 1;
  }
  return Object.entries(counts).sort((a, b) => b[1] - a[1]).slice(0, k);
}
  • 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.

Code, Stage 2: after your review. A small change, and the kind interviewers want to see you catch.

/** After review: a Map has no inherited keys, and the tie-break makes the output repeatable. */
const byCountThenName = (a: [string, number], b: [string, number]) => b[1] - a[1] || a[0].localeCompare(b[0]);

export function topErrors(entries: Iterable<LogEntry>, k: number): [string, number][] {
  const counts = new Map<string, number>();
  for (const e of entries) {
    if (e.level === "ERROR") counts.set(e.service, (counts.get(e.service) ?? 0) + 1);
  }
  return [...counts].sort(byCountThenName).slice(0, k);
}
  • 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.

Code, 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.

/** Stage 3, for millions of lines: read a stream, and keep only k candidates in a min-heap. */
export function topErrorsFast(lines: Iterable<string>, k: number): [string, number][] {
  const counts = new Map<string, number>();
  for (const line of lines) {
    const e = parseLine(line);
    if (e?.level === "ERROR") counts.set(e.service, (counts.get(e.service) ?? 0) + 1);
  }
  if (k <= 0) return [];
  const heap: [string, number][] = [];
  // The root is the entry that ranks last, so it is the one to replace.
  const ranksLater = (a: [string, number], b: [string, number]) => byCountThenName(a, b) > 0;
  const up = (start: number) => {
    let i = start;
    while (i > 0) {
      const p = (i - 1) >> 1;
      if (!ranksLater(heap[i], heap[p])) break;
      [heap[i], heap[p]] = [heap[p], heap[i]];
      i = p;
    }
  };
  const down = () => {
    let i = 0;
    for (;;) {
      let top = i;
      for (const c of [2 * i + 1, 2 * i + 2]) if (c < heap.length && ranksLater(heap[c], heap[top])) top = c;
      if (top === i) return;
      [heap[i], heap[top]] = [heap[top], heap[i]];
      i = top;
    }
  };
  for (const item of counts) {
    if (heap.length < k) {
      heap.push(item);
      up(heap.length - 1);
    } else if (ranksLater(heap[0], item)) {
      heap[0] = item;
      down();
    }
  }
  return heap.sort(byCountThenName);
}
  • 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.

  • Failure, 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.

  • Failure, Going silent while it writes: Use the wait: review the last piece, or say what you'll do next.

  • Failure, 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.

  • Failure, Polishing too early: Naming and tiny optimisations can wait until the core works.

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.

Sources: