Ctrl K

Numbers That Survive a Flip

Medium
Turn a sign with a number on it by 180° and the digits 0, 1 and 8 stay the same, 6 becomes 9 and 9 becomes 6. Every other digit stops being a digit at all. Call a number *flip-proof* if it reads exactly the same after that turn. For example, 69 and 818 are flip-proof, while 16 is not. Return every flip-proof number of length length as a string. Numbers have no leading zeros: the first digit cannot be 0 unless the number is a single digit. The order of the answer doesn't matter.
Example 1
length=1 → ['0', '1', '8']

Among single digits only 0, 1 and 8 stay themselves after the turn.

Example 2
length=3 → ['101', '808', '609', '906', '111', '818', '619', '916', '181', '888', '689', '986']

The outer digits are one of the pairs 1…1, 8…8, 6…9, 9…6, and the middle is 0, 1 or 8: 4 · 3 = 12 numbers.

Constraints
  • 1 ≤ length ≤ 14
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsFlip-Proof Numbers in a Range HardAnagram Buckets MediumWord Traced on a Letter Grid MediumSplit Into Dictionary Words MediumBiggest Number From Pieces Medium
loading Python…
Input
length=1
Expected
['0', '1', '8']

Run checks the first 3 tests in your browser. Submit checks all 11 tests on the server, hidden ones included.