This question evaluates understanding of grid and string manipulation, coordinate transformations, spatial reasoning, and character validation in constrained inputs.
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:
(r, c)
moves to
(2 - r, 2 - c)
.
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.
Return the rotated 3×3 grid (same format) if every cell can be rotated successfully; otherwise return the string "INVALID".
grid
: array of 3 strings, each of length 3, containing digits.
"INVALID"
.
["169", "808", "001"]
["100", "808", "691"]
["123","456","789"]
→
"INVALID"
(contains digits not rotatable)