AlgoForge
LearnPracticeMockPricing
AlgoForge

Master DSA patterns and ace your next technical interview.

Learn

  • Curriculum
  • Problems
  • Daily Challenge
  • Mock Interview

Account

  • Dashboard
  • Pricing
  • Sign In
  • Get Started

Company

  • Privacy Policy
  • Terms of Service

© 2026 AlgoForge. All rights reserved.

Built for engineers who ship.

mediumRecursion

Reverse Integer

## Problem

Given a signed 32-bit integer `x`, return `x` with its digits reversed. If reversing `x` causes the value to go outside the signed 32-bit integer range `[-2^31, 2^31 - 1]`, return `0`.

**Assume the environment does not allow you to store 64-bit integers (signed or unsigned).**

Examples

Input
x = 123
Output
321
Reversed digits: 321.
Input
x = -123
Output
-321
Sign is preserved.
Input
x = 120
Output
21
Leading zero dropped.
Input
x = 1534236469
Output
0
Reversed overflows 32-bit int.

Constraints

-2^31 <= x <= 2^31 - 1
Python
Loading...