Strobogrammatic Number II - Problem
Given an integer n, return all the strobogrammatic numbers that are of length n. You may return the answer in any order.
A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside down).
The valid strobogrammatic digits are: 0, 1, 6, 8, 9 where:
0rotates to01rotates to16rotates to98rotates to89rotates to6
Input & Output
Example 1 — Small Case
$
Input:
n = 2
›
Output:
["11","69","88","96"]
💡 Note:
All 2-digit strobogrammatic numbers: 11 (1↔1), 69 (6↔9), 88 (8↔8), 96 (9↔6)
Example 2 — Single Digit
$
Input:
n = 1
›
Output:
["0","1","8"]
💡 Note:
Single digits that look the same upside down: 0, 1, and 8
Example 3 — Larger Case
$
Input:
n = 4
›
Output:
["1001","1111","1691","1881","1961","6009","6119","6699","6889","6969","8008","8118","8698","8888","8968","9006","9116","9696","9886","9966"]
💡 Note:
4-digit numbers built by adding valid pairs around 2-digit strobogrammatic numbers, excluding those with leading zeros
Constraints
- 0 ≤ n ≤ 14
Visualization
Tap to expand
Understanding the Visualization
1
Input
Length n = 2
2
Valid Digits
Use pairs: 0↔0, 1↔1, 6↔9, 8↔8, 9↔6
3
Output
All valid 2-digit strobogrammatic numbers
Key Takeaway
🎯 Key Insight: Build strobogrammatic numbers recursively by placing valid digit pairs symmetrically from outside to inside
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code