468. Strobogrammatic Number II
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).
Example 1:
Input: n = 2
Output: ["11","69","88","96"]
Explaination :
We need all 2-digit numbers that remain the same when rotated 180 degrees.
- "11" ā 1 stays 1, 1 stays 1 ā Still "11" after rotation.
- "69" ā 6 becomes 9, 9 becomes 6 ā Still "69" after rotation.
- "88" ā 8 stays 8, 8 stays 8 ā Still "88" after rotation.
- "96" ā 9 becomes 6, 6 becomes 9 ā Still "96" after rotation.
So, the valid strobogrammatic numbers of length 2 are ["11", "69", "88", "96"].
It can be proven that there are only 4 strobogrammatic numbers possible fo n = 2.
Example 2:
Input: n = 1
Output: ["0", "1", "8"]
Explanation:
We need all 1-digit numbers that remain the same when rotated 180 degrees.
- "0" ā 0 stays 0 ā Still "0" after rotation.
- "1" ā 1 stays 1 ā Still "1" after rotation.
- "8" ā 8 stays 8 ā Still "8" after rotation.
So, the valid strobogrammatic numbers of length 1 are ["0", "1", "8"].
It can be proven that there are only 3 strobogrammatic numbers possible for n = 1.
Now Your Turn!
Pick the correct output for the given inputInput : n = 3
Still unsure what the problem is asking ?
Letās go through a few more examples, step by step, to make it clearer.