Reverse Integer Problem Statement

Given a 32-bit signed integer N, your task is to return the reversed integer. If reversing the integer causes overflow, return -1.

Input:

The first line contains an integer 'T', the number of test cases.
Each test case consists of a single line containing a 32-bit signed integer 'N'.

Output:

For each test case, return the reversed integer of 'N'.
Output each result on a new line.

Example:

Input:
3
123
-123
120
Output:
321
-321
21

Constraints:

  • 1 <= T <= 5
  • -231 <= N <= 231 - 1
  • Time limit: 1 sec

Note:

Do not use data types with more than 32-bit capacity. Assume the environment does not allow storing 64-bit integers. You do not need to print anything; implementation of the function is required.
AnswerBot
3d

The task is to reverse a 32-bit signed integer and handle overflow cases.

  • Create a function that takes a 32-bit signed integer as input

  • Reverse the integer while handling overflow cases

  • Return the revers...read more

Shiv Lal
2y

Implementation The idea is to use the fact that the input ‘N’ is a 32 bit signed integer. So, as mentioned, -2147483648 <= ‘N’ <= 2147483647. In this range, for ‘N’ = 10 * x + y, the ‘N’ can never at...read more

Help your peers!
Add answer anonymously...
Larsen & Toubro Limited Full Stack Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter