TryBugHunt
🐛 Daily Bug #780A new bug every day · Same bug for everyone
pythonType errorMedium

AI Attempt: Reversing a negative number crashes

🤖 AI Code ReviewSpot the flaw in the AI assistant's solution

An AI assistant wrote this implementation with complete confidence. It passes standard inputs, but fails on a subtle edge case — the exact skill tested in modern AI-assisted interview rounds. Audit the logic, isolate what the model missed, and make it production-ready.

What it should do

An AI assistant wrote this for a classic interview question. reverse_number(n) reverses the digits of a whole number and keeps its sign. Example: reverse_number(123) → 321, reverse_number(-123) → -321.

What happens instead

reverse_number(-123) crashes: ValueError: invalid literal for int() with base 10: '321-'.

def reverse_number(n):
    return int(str(n)[::-1])

Test a custom input to verify an edge case (e.g. empty lists, negative numbers, duplicates).

⏱️0:00
Hints
🏆 0 hints = Flawless Solve
Think & Test Cooldown
2:00 remaining

Take a moment to read the bug symptom and trace the code with Run & Check before unlocking Hint 1.

Hint 2
Unlocks after Hint 1
Hint 3
Unlocks after Hint 2

This bug belongs to the type errors pattern

Strings that look like numbers, totals that refuse to add, comparisons between str and int.