Question: please finish the code in python and keep the time for running the code within 1000ms.Thankyou MaxMagicSquare Description A magic square of size K is
please finish the code in python and keep the time for running the code within 1000ms.Thankyou



MaxMagicSquare Description A magic square of size K is a K x K square grid filled with integers such that the sum of the integers in each row, column and di agonal of the grid is equal. For instance the following diagram shows a magic square of size 3. The top row has a sum of 7 + 3 + 8 = 18, the last column h as a sum of 8 +5+5 = 18 and one of the two diagonals has a sum of 4 + 6 + 8 = 18. Every other row and column (and the sec ond diagonal) also has a sum of 18: 7 3 8 7 6 5 4 9 5 Note that integers in the magic square do not have to be distinct. Also note that every square of size 1 is magic. Write a function: | def solution(A) that, given a matrix A consisting of N rows and M columns, returns the size of the largest magic square that can be found withi n this matrix. Examples: Given matrix A with four rows and five columns: 0 1 2 3 4 0 1 4 3 4 53 2 7 3 8 4 7 6 5 2 2 1 3 8 4 9 5 5 the function should return 3. The sum of the integers in each row, column and diagonal of the largest magic square is equal to 18. Assume that: N and M are integers within the range (1..20); each element of matrix A is an integer within the range [1..100,000]. Input First row contain two integers, representing N and M. And the following lines representing a N by M matrix. Output the size of the largest magic square that can be found within the matrix Sample Input 1 Sample Output 1 3 4,5 4,3,4,5,3 2,7,3,8,4 1,7,6,5,2 8,4,9,5,5 Language: Python3 Theme: Solarized Light 1 2 3 4. 5 def solution (A): # write your code in Python 3.6 pass if name == 6 7 8 main ": n_rows, n_cols = tuple([ int(v) for v in input().split(",") }) matrix = [[ int(v) for v in input().split(",) ] for _ in range(n_rows) ] print( solution(matrix)) . 10
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
