/Interview

AI interview hacks · Lesson 2 of 6 · 15 min

Make AI plant bugs in good code

Study with AI

Part 1Basics

When AI writes the code, your job moves from typing to reviewing. Canva says it scores finding and fixing problems in AI-generated code. Most people have never practised that on purpose.

This drill is simple. Take code you know works, change a few small things so it's wrong, and find the changes. Because you know exactly what was planted, you get an honest score.

Words you need

Mutation
A tiny change to working code, such as turning <= into <. Mutation testing uses the same idea to check whether tests catch bugs.
False alarm
A line you flagged that was actually fine. Too many waste time in a real round.
Seed
A number that makes random choices repeatable, so the same seed plants the same bugs.

A worked example

Meera can write code quickly, but she reads it slowly. She runs the planter on her own binary search with a seed of 42, and gets three bugs. She finds two in nine minutes and misses the third, a changed boundary. A week later, she finds all three in four minutes.

Part 2The question

How do you get faster at spotting mistakes in code you didn't write?

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

  • Plant bugs with a script or a prompt
  • Review code against a checklist
  • Track found, missed and false alarms

Part 3In detail

Step by step

  1. Pick code you trust. Your own solutions, or code with passing tests.
  2. Plant three bugs. Use the script here, or the prompt for harder logic bugs.
  3. Set a timer and read. Don't run anything. Read for boundaries, empty input, and wrong conditions.
  4. Say each bug out loud. Say what breaks and which input proves it.
  5. Score it. Compare against the planted list, then run the tests to confirm.

Script or prompt?

The script makes small syntax-level changes, which build speed. An AI prompt can plant subtle logic bugs, such as a cache that never refreshes. Use both, but keep the answer key hidden until you've finished.

Prompts to copy

Plant logic bugs

Keep the answers in a separate message, or ask for them after your attempt.

Here is working code:
[code]
Make a copy with 3 realistic bugs of the kind AI assistants often write: a missed edge case, a wrong assumption about input, and one performance trap. Keep it plausible, with no comments that give it away. Show only the changed code. List the bugs only when I say 'answers'.

The code, explained

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

Planting the bugs

Finds the places a small change is possible, then picks a few using a repeatable random order.

BugPlanter.tsTypeScript
1/** A seeded generator gives the same bugs for the same seed, so you can check your answers later. */2function seeded(seed: number): () => number {3  let s = seed >>> 0;4  return () => {5    s = (s + 0x6d2b79f5) >>> 0;6    let t = s;7    t = Math.imul(t ^ (t >>> 15), t | 1);8    t ^= t + Math.imul(t ^ (t >>> 7), t | 61);9    return ((t ^ (t >>> 14)) >>> 0) / 4294967296;10  };11}12 13export function plantBugs(code: string, count: number, seed: number): { code: string; planted: Planted[] } {14  const random = seeded(seed);15  const lines = code.split("\n");16  const options: { line: number; rule: number }[] = [];17  lines.forEach((text, line) => {18    if (text.trim().startsWith("//")) return;19    RULES.forEach(([re], rule) => {20      if (re.test(text)) options.push({ line, rule });21    });22  });23  const planted: Planted[] = [];24  while (planted.length < count && options.length > 0) {25    const [pick] = options.splice(Math.floor(random() * options.length), 1);26    if (planted.some((p) => p.line === pick.line + 1)) continue; // at most one bug per line27    const before = lines[pick.line];28    const [re, to] = RULES[pick.rule];29    lines[pick.line] = before.replace(re, to);30    planted.push({ line: pick.line + 1, before: before.trim(), after: lines[pick.line].trim() });31  }32  planted.sort((a, b) => a.line - b.line);33  return { code: lines.join("\n"), planted };34}
34 linesUTF-8TypeScript
function seeded(seed: number)
A tiny random generator. Math.random can't be repeated, and this can.
text.trim().startsWith("//")
Skips comments, because changing a comment plants no bug.
planted.some((p) => p.line === pick.line + 1)
At most one bug per line, which makes scoring fair.
planted.sort
The answer key comes out in line order.

Tested by npm run test:modules.

Scoring your review

Three numbers tell you more than a pass or fail.

BugPlanter.tsTypeScript
1export function scoreReview(planted: Planted[], linesYouFlagged: number[]) {2  const found = planted.filter((p) => linesYouFlagged.includes(p.line)).length;3  const falseAlarms = linesYouFlagged.filter((l) => !planted.some((p) => p.line === l)).length;4  return { found, missed: planted.length - found, falseAlarms };5}
5 linesUTF-8TypeScript
falseAlarms
Lines you flagged that were fine. In a live round, these burn time.
missed
The bugs that would have reached production.

Tested by npm run test:modules.

What can go wrong

Running it right away
Tests find the bug for you. Read first, then run.
Only planting easy bugs
Mix in the prompt version, or you'll only get good at spotting syntax-level slips.

Part 4Questions and answers

Answer out loud first, then open each one.

Why use a seed?
The same seed plants the same bugs, so you can repeat a drill and measure progress, and check your answers later.
What should you look at first when reading unfamiliar code?
Boundaries, empty input, conditions, and anything that changes state. Most planted and real bugs live there.

Part 5Going further

Drill: Three bugs against the clock (15 min)

  1. Plant 3 bugs in code you wrote this week.
  2. Read with no running for up to 10 minutes.
  3. Write down the line and the input that breaks it.
  4. Score it: found, missed, false alarms.

Score yourself

Tick a line only if you did it without prompting.

0 of 3 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: the hack that fixes how you sound, using a recording and a small script.

Next: Talk track →

← Never ask AI for the answer

AI Engineer · AI interview hacks