KatInterview

Seven-Segment Display 180° Rotation Symmetry

Arrays & HashingAuto-graded · 28 test cases
MediumAuto-gradedArrays & Hashingarrayssimulationmapping

Last updated

Determine if a sequence of seven-segment digits appears identical when the entire display is flipped upside down.

You have a digital display showing a sequence of decimal digits (0-9), each rendered on a standard seven-segment LED cell. Your task is to determine whether the entire display would look identical if physically rotated 180 degrees.

Each seven-segment cell contains these segments:

  • a: top horizontal
  • b: top-right vertical
  • c: bottom-right vertical
  • d: bottom horizontal
  • e: bottom-left vertical
  • f: top-left vertical
  • g: middle horizontal

The standard segment patterns for digits are:

DigitActive Segments
0a, b, c, d, e, f
1b, c
2a, b, d, e, g
3a, b, c, d, g
4b, c, f, g
5a, c, d, f, g
6a, c, d, e, f, g
7a, b, c
8a, b, c, d, e, f, g
9a, b, c, d, f, g

When you rotate the entire display 180 degrees:

  1. The order of cells reverses (first becomes last, last becomes first)
  2. Within each cell, segments transform as follows:
    • a ↔ d (top and bottom swap)
    • b ↔ e (top-right and bottom-left swap)
    • c ↔ f (bottom-right and top-left swap)
    • g → g (middle stays in place)

Return True if and only if the rotated display shows exactly the same digit sequence. Note that a rotated cell must produce a valid digit pattern (one of 0-9); if rotation produces an unrecognized pattern, the display cannot match.

Constraints

  • 1 <= len(digits) <= 10^5
  • 0 <= digits[i] <= 9

Examples

Example 1

Input: is_display_symmetric([6, 0, 9])

Output: True

Example 2

Input: is_display_symmetric([8, 1, 8])

Output: False

Example 3

Input: is_display_symmetric([2, 5])

Output: False

Hints

Hint 1

First determine which digits remain valid after their segments are rotated. Some digit patterns become invalid or transform into different digits.

Hint 2

The display reverses left-to-right when rotated, so the digit at position i must match what the digit at position n-1-i becomes after its segments are transformed.

Hint 3

Build a lookup table mapping each digit to what it becomes after rotation. Use -1 or None for digits whose rotated pattern doesn't correspond to any valid digit.