Magic Squares In Grid
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
A 3 x 3 *magic square* here means a 3 x 3 block that contains each integer from 1 to 9 exactly once, and in which all three rows, all three columns, and both diagonals have the same sum.
Given an m x n integer matrix grid (values range from 0 to 15), count how many contiguous 3 x 3 subgrids are magic squares. Subgrids may overlap.
Return that count as an integer (return 0 if the grid is smaller than 3 x 3).
Examples
Constraints
- `1 <= m, n <= 10`
- `0 <= grid[i][j] <= 15`
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.