Skip to content
spot_the_ai_bug

Inverted logic: interview questions

Inverted logic does exactly the opposite of what was intended: a missing or extra !, ASC instead of DESC, or keeping what should be removed.

How to spot it in code review

  • Read each condition out loud and compare it to the requirement.
  • Check what filter() and WHERE keep, not what they drop.
  • Write the one-line test: does a known-good input pass?
  • Be extra careful with double negatives.

Why AI-generated code gets this wrong

Models autocomplete the shape of a familiar line and can flip a single character; the code compiles either way.

Inverted logic: 3 practice questions

Pending tasks filter

The "To do" tab shows the result of pendingTasks(). Users say it lists the tasks they already finished. Find the bug.

interface Task {  id: string;  title: string;  done: boolean;} export function pendingTasks(tasks: Task[]): Task[] {  return tasks.filter((task) => task.done);}
Show answer

line 8 · Logic inverted

filter keeps the items for which the callback returns true, so this keeps the completed tasks. Pending tasks are the ones where done is false.

Fix
  return tasks.filter((task) => !task.done);

Interview follow-up: A quick unit test with one done and one pending task catches this instantly; say so.

Q2Goeasy

Upload file-type check

validateUpload() should only accept PNG files. What does it actually allow?

var errNotPNG = errors.New("only .png files are allowed") func validateUpload(filename string) error {	if !strings.HasSuffix(strings.ToLower(filename), ".png") {		return nil	}	return errNotPNG}
Show answer

line 4 · Logic inverted

The condition is inverted: every file that is not a PNG passes validation, and real PNGs are rejected.

Fix
	if strings.HasSuffix(strings.ToLower(filename), ".png") {		return nil	}	return errNotPNG

Interview follow-up: Also point out that extensions are user-controlled; check the file's magic bytes (http.DetectContentType) for real validation.

Q3SQLeasy

Leaderboard top 10

This query feeds the "Top 10 players" leaderboard. Why is the leaderboard full of beginners?

SELECT player_id, MAX(score) AS best_scoreFROM game_resultsGROUP BY player_idORDER BY best_score ASCLIMIT 10;
Show answer

line 4 · Logic inverted

ASC sorts from lowest to highest, so LIMIT 10 keeps the ten worst scores. A top-N query needs descending order.

Fix
ORDER BY best_score DESC

Interview follow-up: Also discuss ties: should players with equal scores share a rank (RANK() vs ROW_NUMBER())?

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