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 input

Input : n = 3

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Hints

Frequently Occurring Doubts

Interview Follow-up Questions

Fun Facts

0
class Solution {
public:
vector<string> findStrobogrammatic(int n) {
// Your code goes here
}
};
Test Case

Input:

N