Skip to main content

Reverse Integer

Reverse digits of an integer. Return 0 if overflow. Example: 123 => 321, -123 => -321

Reverse Integer is one of those problems where a small math insight beats brute force. Interviewers love it because it reveals your turning constraints into math and your edge-case discipline. The trap is brute force: there's almost always a simplification hiding in the constraints.

Math & Geometry

Examples

You write

reverse(x: int)

  1. Example 1

    Input
    123
    returns
    321
  2. Example 2

    Input
    -123
    returns
    -321

Meet Coco

Coco is an AI study partner, not a person. She listens while you explain your code, asks what a line does and never hands you the fix. Sign in free to type with Coco, up to a daily limit. The editor and Run stay open without an account. Anyone can open the editor and run their code.

1Reverse Integermedium