Question: Given a square matrix, calculate the a b s o l u t e difference between the sums o f its diagonals. For example, the
Given a square matrix, calculate the difference between the sums its diagonals.
For example, the square matrix arr shown below:
The leftright diagonal The right left diagonal Their
difference
Function description Output Format
Return the absolute difference between the sums of the matrix's two diagonals as a single integer.
Explanation
The primary diagonal is:
Sum across the primary diagonal:
The secondary diagonal is:
Sum across the secondary diagonal:
Difference:
Note: is the absolute value of
Complete the diagonalDifference function the editor below.
diagonalDifference takes the following parameter:
int arr: array integers
Return
int: the diagonal difference
Input Format
The first line contains a single integer, the number rows and columns the square matrix arr.
Each the next lines describes a row, arr and consists spaceseparated integers arr
Constraints
arr
Solve the problem in Python programming language with explanation for each step so that it can be understood
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
