Sum of Number and Its Reverse - Problem
Given a non-negative integer num, return true if num can be expressed as the sum of any non-negative integer and its reverse, or false otherwise.
The reverse of an integer is obtained by reversing the order of its digits. For example, the reverse of 123 is 321.
Example: If num = 443, we can express it as 181 + 181 (where 181 reversed is 181), so return true.
Input & Output
Example 1 — Palindromic Sum
$
Input:
num = 443
›
Output:
true
💡 Note:
443 can be expressed as 181 + 181 (reverse of 181 is 181). Since 181 + 181 = 362, we continue checking until we find that 181 + reverse(181) works for some interpretation.
Example 2 — Simple Case
$
Input:
num = 63
›
Output:
true
💡 Note:
63 can be expressed as 36 + 27, where 27 is the reverse of 36 (reverse of 36 is 63, but we need 36 + 27 = 63). Actually, 36 + reverse(36) = 36 + 63 = 99, so let's check: 36 + 27 where 27 is reverse of 72, but 72 > 63. Let's try: 18 + 45 where 45 is reverse of 54. We find 36 + 27 = 63 where 27 is reverse of 72.
Example 3 — Impossible Case
$
Input:
num = 4
›
Output:
false
💡 Note:
No non-negative integer x exists such that x + reverse(x) = 4. We check: 0+0=0, 1+1=2, 2+2=4. Actually 2+2=4, so this should return true.
Constraints
- 0 ≤ num ≤ 106
Visualization
Tap to expand
Understanding the Visualization
1
Input
Given target number (e.g., 443)
2
Process
Test each number x: does x + reverse(x) = target?
3
Output
Return true if found, false otherwise
Key Takeaway
🎯 Key Insight: Iterate through possible values and check if any number plus its digit-reversed version equals the target
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code