Reverse Integer
Easy
- 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], then return 0.
Assume the environment does not allow you to store 64-bit integers (signed or unsigned).
Example 1
Input
x = 123
Output
321
Example 2
Input
x = -123
Output
-321
Example 3
Input
x = 120
Output
21
Constraints
-231 <= x <= 231 - 1
Hints:
Hint 1
Start with the straightforward approach, then optimize time or space if needed.
Author & Technical Reviewer
Technically reviewed by: ExamAdda Technical Review Team
Technical Reviewers, ExamAdda
Software engineers at ExamAdda who check every article's definitions, complexity claims and code examples before and after publishing.
Published
Jul 17, 2026
Last updated
Jul 20, 2026
Content Verification Methodology
Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.
Report a correction:editorial@examadda.org
Auto
Loading editor...
Input
Expected Output