Skip to content

Solution to the challenge in HackerRank under Algorithms section.

Notifications You must be signed in to change notification settings

suryakanth96/Diagonal-Difference

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Diagonal-Difference

Solution to the challenge in HackerRank under Algorithms section.

Given a square matrix of size NxN , calculate the absolute difference between the sums of its diagonals.

Input Format

The first line contains a single integer,N . The next N lines denote the matrix's rows, with each line containing N space-separated integers describing the columns.

Constraints

-100<=Elements in the matrix<=100

Output Format

Print the absolute difference between the two sums of the matrix's diagonals as a single integer.

Sample Input

3 11 2 4 4 5 6 10 8 -12 Sample Output

15 Explanation

The primary diagonal is:

11 5 -12 Sum across the primary diagonal: 11 + 5 - 12 = 4

The secondary diagonal is:

 4

5 10 Sum across the secondary diagonal: 4 + 5 + 10 = 19 Difference: |4 - 19| = 15

About

Solution to the challenge in HackerRank under Algorithms section.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages