Rotate a 3×3 digit grid by 180°
Company: Microsoft
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
## Problem
You are given a **3×3** grid of digits (characters `'0'`–`'9'`), represented as an array of 3 strings of length 3.
When the entire grid is rotated by **180 degrees**:
1. Each cell `(r, c)` moves to `(2 - r, 2 - c)`.
2. Each digit must also be replaced by what it looks like after a **180-degree rotation**.
Assume only the following digits remain valid under 180° rotation:
- `0 → 0`
- `1 → 1`
- `8 → 8`
- `6 → 9`
- `9 → 6`
All other digits (`2,3,4,5,7`) become invalid.
### Task
Return the rotated 3×3 grid (same format) if every cell can be rotated successfully; otherwise return the string `"INVALID"`.
### Input/Output
- **Input:** `grid`: array of 3 strings, each of length 3, containing digits.
- **Output:** array of 3 strings (rotated grid) or `"INVALID"`.
### Examples
- Input:
- `["169",
"808",
"001"]`
- Output:
- `["100",
"808",
"691"]`
- Input: `["123","456","789"]` → `"INVALID"` (contains digits not rotatable)
Quick Answer: This question evaluates understanding of grid and string manipulation, coordinate transformations, spatial reasoning, and character validation in constrained inputs.
Rotate a 3x3 digit grid and transform each digit under 180-degree rotation, or return INVALID.
Constraints
- grid has three strings of length three
Examples
Input: (['169', '808', '001'],)
Expected Output: ['100', '808', '691']
Explanation: Prompt example.
Input: (['123', '456', '789'],)
Expected Output: 'INVALID'
Explanation: Invalid digits.
Input: (['000', '111', '888'],)
Expected Output: ['888', '111', '000']
Explanation: Self-rotating digits.
Hints
- Read destination cells from the opposite source cell and map each digit.