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:

  • 00
  • 11
  • 69
  • 88
  • 96
  • 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
Strobogrammatic Number: 180° Rotation TestOriginal: '69'69After 180° RotationRotate & ReverseRotated: '69'696 → 99 → 6Reversed: 69Comparison: '69' == '69'✓ Strobogrammatic Number!
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
Asked in
Google 45 Facebook 38 Microsoft 25
28.0K Views
Medium Frequency
~15 min Avg. Time
892 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