A retro scoreboard widget can show a counter mirrored: its digits in reverse order, keeping the sign. The scoreboard only stores 32-bit signed integers, from -2147483648 to 2147483647.
Write mirrorCounter(n) that returns n with its digits reversed and the same sign (1230 becomes 321). If the mirrored value doesn't fit in the 32-bit range, return 0.
Input: n = 1230 Output: 321
The digits 1230 reversed are 0321, which is 321.
Input: n = -45 Output: -54
The digits reverse and the sign stays.
-2^31 <= n <= 2^31 - 1Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #657 Mirror a Signed Counter. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.