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:
-
Each cell
(r, c)
moves to
(2 - r, 2 - c)
.
-
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:
-
Input:
["123","456","789"]
→
"INVALID"
(contains digits not rotatable)