Skip to content
This repository has been archived by the owner on Nov 3, 2024. It is now read-only.

Hacktober-Vest2024 #455

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions Beginner Level πŸ“/Diagonal Difference/question.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
matrix, calculate the absolute difference between the sums of its diagonals.

For example, the square matrix arr is shown below:

1 2 3
4 5 6
9 8 9

The left-to-right diagonal = 1+ 5 + 9 = 15.
.The right to left diagonal = 3 +5 +9 = 17 . Their absolute difference is
|15-17| = 2 .
.

Function description

Complete the diagonal difference function in the editor below.

diagonalDifference takes the following parameter:

int arr[n][m]: an array of integers

Return

int: the absolute diagonal difference

Input Format

The first line contains a single integer, n, the number of rows and columns in the square matrix arr .
Each of the next n lines describes a row, arr[i] , and consists of n space-separated integers arr[i][j]

.Constraints

-100 <= a[i][j] <= 100

Output Format

Return the absolute difference between the sums of the matrix's two diagonals as a single integer.
17 changes: 17 additions & 0 deletions Beginner Level πŸ“/Diagonal Difference/solution.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
N=int(input())
grid=[]
for i in range(0,N):
lists=[int(i) for i in input().split()]
grid.append(lists)
count=0
sum1=0
sum2=0
j1=0
j2=N-1
while(count<N):
sum1=sum1+grid[count][j1]
sum2=sum2+grid[count][j2]
count+=1
j1+=1
j2-=1
print(abs(sum1-sum2))
5 changes: 4 additions & 1 deletion Beginner Level πŸ“/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@
"name": "Vimal M",
"githubUsername": "vimall03"
},

{
"name": "Chris",
"githubUsername": "Gen0z"
},
]