Confusing Number - Problem
A confusing number is a number that when rotated 180 degrees becomes a different number with each digit valid.
We can rotate digits of a number by 180 degrees to form new digits:
- When
0, 1, 6, 8, 9are rotated 180 degrees, they become0, 1, 9, 8, 6respectively - When
2, 3, 4, 5, 7are rotated 180 degrees, they become invalid
Note: After rotating a number, we can ignore leading zeros. For example, after rotating 8000, we have 0008 which is considered as just 8.
Given an integer n, return true if it is a confusing number, or false otherwise.
Input & Output
Example 1 — Single Confusing Digit
$
Input:
n = 6
›
Output:
true
💡 Note:
When rotated 180°, digit 6 becomes 9. Since 6 ≠ 9, it's a confusing number.
Example 2 — Two-Digit Confusing Number
$
Input:
n = 89
›
Output:
true
💡 Note:
8 rotates to 8, 9 rotates to 6. Rotated number is 68. Since 89 ≠ 68, it's confusing.
Example 3 — Invalid Digit
$
Input:
n = 11
›
Output:
false
💡 Note:
Both 1s rotate to 1s, giving 11. Since 11 = 11, it's not confusing (same number).
Constraints
- 0 ≤ n ≤ 109
Visualization
Tap to expand
Understanding the Visualization
1
Input
Given number with potentially rotatable digits
2
Validation
Check if all digits are rotatable (0,1,6,8,9)
3
Rotation
Apply 180° rotation mapping to each digit
4
Comparison
Compare rotated result with original
Key Takeaway
🎯 Key Insight: A number is confusing if it contains only rotatable digits AND becomes a different number when rotated 180°
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code