Does a Seven-Segment LED Digit Display Read the Same Rotated 180 Degrees?
Company: Waymo
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
An LED display shows a row of digits from 0 to 9, one digit per seven-segment cell. Write a function that decides whether the display reads exactly the same after the whole display is rotated by 180 degrees.
### Function Signature
```python
def looks_same_after_rotation(digits: list[int]) -> bool:
```
### Rules
- Each cell has seven segments: `a` (top), `b` (upper right), `c` (lower right), `d` (bottom), `e` (lower left), `f` (upper left) and `g` (middle).
- The digits light these segments:
| Digit | Lit segments |
|---|---|
| 0 | a, b, c, d, e, f |
| 1 | b, c |
| 2 | a, b, d, e, g |
| 3 | a, b, c, d, g |
| 4 | b, c, f, g |
| 5 | a, c, d, f, g |
| 6 | a, c, d, e, f, g |
| 7 | a, b, c |
| 8 | a, b, c, d, e, f, g |
| 9 | a, b, c, d, f, g |
- Rotating the display by 180 degrees reverses the left-to-right order of the cells, and inside every cell it moves segment `a` to `d`, `d` to `a`, `b` to `e`, `e` to `b`, `c` to `f`, `f` to `c`, and leaves `g` in place.
- Return `True` if and only if, after the rotation, every cell shows exactly the same set of lit segments as the cell in that position showed before. A rotated cell whose segment pattern is not one of the ten digits above can never match.
### Constraints
- `1 <= len(digits) <= 10^5`
- `0 <= digits[i] <= 9`
### Examples
**Example 1**
- Input: `digits = [6, 0, 9]`
- Output: `True`
- Explanation: After rotation the cells appear in reverse order, and each rotated cell shows: 9 becomes 6, 0 stays 0, 6 becomes 9. The display reads 6, 0, 9 again.
**Example 2**
- Input: `digits = [8, 1, 8]`
- Output: `False`
- Explanation: The 1 lights segments `b` and `c`; rotated, it lights `e` and `f`, which is a bar on the left side of the cell and not the pattern for 1.
**Example 3**
- Input: `digits = [2, 5]`
- Output: `False`
- Explanation: Each of 2 and 5 looks like itself after rotation, but the cell order is reversed, so the display reads 5, 2.
Overview: Decide whether a row of digits on a seven-segment LED display reads the same after the whole display is rotated by 180 degrees. Tests modeling each digit as lit segments, mapping segments under rotation, and comparing the reversed display.