Skip to content
spot_the_ai_bug

Edge-case bugs: interview questions

Edge-case bugs work for typical inputs and break at the boundaries: zero, empty collections, the last day of a month, non-ASCII text.

How to spot it in code review

  • Run through 0, 1, empty and maximum inputs before anything else.
  • Look for truthiness checks that also catch 0 or "".
  • Look for division and indexing that assume a non-empty input.
  • Ask what the caller expects for "no data".

Why AI-generated code gets this wrong

Training examples are usually happy-path, so the boundary case that never appears in examples never gets handled.

Edge-case bugs: 3 practice questions

Q1Pythonmedium

Last N items with a slice

last_n() powers the "recent activity" widget. A user set their widget size to 0. What do they see?

def last_n(items: list, n: int) -> list:    """Return the last n items (n >= 0)."""    if n < 0:        raise ValueError("n must be non-negative")    return items[-n:]
Show answer

line 5 · Wrong edge case

When n is 0, -n is also 0, and items[0:] is the whole list. Asking for zero items returns everything.

Fix
    return items[max(len(items) - n, 0):]

Interview follow-up: Interviewers like this one because the code is correct for every n except the boundary. Ask yourself about 0, 1, and n > len(items).

Falsy zero in a stock label

formatStock() renders the stock badge on product cards. What does a sold-out product show?

function formatStock(count) {  if (!count) return "Stock unknown";  if (count < 5) return `Only ${count} left`;  return "In stock";} formatStock(0); // expected a "Sold out" badge
Show answer

line 2 · Wrong edge case

!count is true for 0 as well as for null and undefined, so a sold-out product shows "Stock unknown" instead of being treated as zero stock.

Fix
  if (count == null) return "Stock unknown";  if (count === 0) return "Sold out";

Interview follow-up: Know the falsy values cold: false, 0, -0, 0n, "", null, undefined, NaN.

Q3Goeasy

Average of an empty slice

Average() is used on the latency dashboard. What happens for a service with no requests yet?

// Average returns the mean latency in milliseconds.func Average(latencies []int) int {	sum := 0	for _, l := range latencies {		sum += l	}	return sum / len(latencies)}
Show answer

line 7 · Wrong edge case

With an empty slice, len is 0 and integer division by zero panics at runtime ("integer divide by zero"), crashing the dashboard handler.

Fix
	if len(latencies) == 0 {		return 0	}	return sum / len(latencies)

Interview follow-up: Mention whether 0 is the right answer for "no data", or whether returning (int, bool) is clearer.

Every day, everyone gets the same pull request written by AI. It looks clean. It has comments. It has exactly one real bug.

  1. 1

    Find the line

    Tap the buggy line, then hit Submit. You get 3 attempts.

  2. 2

    Read the hints

    A miss within 2 lines is 🔥 Warm. Anything further is ❄️ Cold.

  3. 3

    Name the bug

    Found it? Bonus round: pick the bug type from 4 options. It doesn't affect your win, just your bragging rights.

// your share card

found in 3/3

🟥 cold miss · 🟨 warm miss · 🟩 found · ⬛ unused

Keyboard: ↑ ↓ to move between lines, Enter to submit. A new bug drops every day at midnight IST.

0
Played
0
Win %
0
Streak
0
Max

Attempts distribution