Fill Matrix
Given a NxN matrix. Fill the integers from 1 to n*n to this matrix that makes the sum of each row, each column and the two diagonals equal.
Example 1 :
Input: n = 2
Output: null
Explanation:
We need to fill [1, 2, 3, 4] into a 2x2 matrix, which is not possible so
return null.
Example 2 :
Input: n = 3
Output: [[8, 3, 4], [1, 5, 9], [6, 7, 2]]
Explanation:
We need to fill [1, 2, 3... 9] into a 3x3 matrix. This is one way to do
it.
Each row [8, 3, 4], [1, 5, 9], [6, 7, 2] sum is 15.
Each column [8, 1, 6], [3, 5, 7], [4, 9, 2] sum is 15.
The two diagonals [8, 5, 2] and [4, 5, 6] sum is 15.
Get one-to-one training from Google Facebook engineers
Top-notch Professionals
Learn from Facebook and Google senior engineers interviewed 100+ candidates.
Most recent interview questions and system design topics gathered from aonecode alumnus.
One-to-one online classes. Get feedbacks from real interviewers.
Customized Private Class
Already a coding expert? - Advance straight to hard interview topics of your interest.
New to the ground? - Develop basic coding skills with your own designated mentor.
Days before interview? - Focus on most important problems in target company question bank.