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, 9 are rotated 180 degrees, they become 0, 1, 9, 8, 6 respectively
  • When 2, 3, 4, 5, 7 are 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
Confusing Number Process: Input → Validation → Rotation → ComparisonInput: 69Check digits:6,9 ∈ {0,1,6,8,9} ✓Rotate digits:6→9, 9→6Result: 9669 ≠ 96 ✓Process: 69 → Check validity → Apply rotation → Compare with originalOutput: true (confusing number)CONFUSING NUMBER
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°
Asked in
Google 15 Facebook 8
12.0K Views
Medium Frequency
~15 min Avg. Time
430 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen