Strobogrammatic Number - Problem
A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).
Given a string num which represents an integer, return true if num is a strobogrammatic number.
When rotated 180 degrees, the digits transform as follows:
0→01→16→98→89→6- All other digits (
2, 3, 4, 5, 7) are invalid when rotated
Input & Output
Example 1 — Valid Strobogrammatic
$
Input:
num = "69"
›
Output:
true
💡 Note:
When rotated 180°: '6' becomes '9' and '9' becomes '6', giving us '96'. Reversed: '69' equals original.
Example 2 — Invalid Digit
$
Input:
num = "88"
›
Output:
true
💡 Note:
Both '8' digits remain '8' when rotated 180°, so '88' rotated is still '88'.
Example 3 — Contains Invalid Digit
$
Input:
num = "962"
›
Output:
false
💡 Note:
The digit '2' cannot be rotated 180° to form a valid digit, so this is not strobogrammatic.
Constraints
- 1 ≤ num.length ≤ 50
- num consists of only digits.
- num does not contain any leading zeros except for the zero itself.
Visualization
Tap to expand
Understanding the Visualization
1
Input
Original number as string
2
Rotation
Each digit rotated 180° and string reversed
3
Comparison
Check if rotated equals original
Key Takeaway
🎯 Key Insight: Use two pointers to validate rotation pairs from both ends simultaneously
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code