Welcome to the Reverse Integer Challenge! This coding problem, inspired by a LeetCode problem, is a common interview question and a great exercise to test your problem-solving and coding skills. The goal is simple: given a 32-bit signed integer, reverse the digits of that integer.
Write a function that takes an integer as its input and returns the integer with its digits reversed. More details can be found on the LeetCode problem page.
- The input is a 32-bit signed integer. Your function should maintain the sign of the integer.
- If the reversed integer overflows (i.e., it's outside the range of a 32-bit signed integer), return 0.
-
Input:
123
Output:321
-
Input:
-123
Output:-321
-
Input:
120
Output:21
-
Input:
0
Output:0
-
Input:
2147533648
Output:0
(outside 32 bit integer) -
Input:
-2147383643
Output:0
(outside 32 bit integer)
- The solution should be written in Programming Language of the Interiew.
- Your function should handle edge cases gracefully and efficiently.
- Unit tests are encouraged to verify the correctness of your solution. (optional)
You can use online coding sandboxes like Replit, CodeSandbox, StackBlitz, or JSFiddle for coding and sharing your solution. Just make sure to provide the link to your code in the submission.
Otherwsie use steps bellow to submit it:
- Fork this repository and create a new branch for your solution.
- Add your solution file to the repository. Please name the file in the following format:
<GitHub_Username>_reverse_integer.[ext]
. - Ensure your code is well-documented and follows the coding standards for the language you're using.
- Create a pull request against the main branch of this repository with your solution, or share the link to your solution.
- In your pull request or shared link, provide a brief explanation of your approach and any assumptions you made while solving the problem.
Your submission will be evaluated based on:
- Correctness: Correctly reverse the digits of the input integer while handling edge cases and overflow? โ
- Code Quality: Is the code readable, well-structured, and maintainable? ๐
- Efficiency: Does the solution perform well with large inputs? ๐
- Testing: Are there unit tests, and do they adequately cover different scenarios? ๐งช (optional)
Good luck, and we look forward to seeing your solution! ๐