a k x k magic square k x k grid fill integer row sum column sum diagonal sum equal the integer magic square distinct every 1 x 1 grid trivially magic squareGiven m x n integer grid return size ie length k large magic square find grid Example 1input grid 71456251641543212734output 3explanation the large magic square size 3every row sum column sum diagonal sum magic square equal 12 row sum 516 543 273 12 Column sum 552 147 633 12 Diagonal sum 543 642 12example 2input grid 513193311338output 2 Constraintsm gridlengthn gridilength1 m n 501 gridij 106