Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add diagonal_difference code in Udemy #1267

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

NeilSenEasow
Copy link

Problem: Diagonal Difference

Description:

The task is to calculate the absolute difference between the sums of a square matrix's two diagonals:

  1. Primary Diagonal: The diagonal that runs from the top-left to the bottom-right of the matrix.
  2. Secondary Diagonal: The diagonal that runs from the top-right to the bottom-left of the matrix.

You are given a n x n matrix (where n is the number of rows and columns), and you need to find the absolute difference between the sums of the primary and secondary diagonals.

Input:

  • The first line contains an integer n, which represents the number of rows and columns of the matrix.
  • The next n lines each contain n space-separated integers representing the matrix elements.

Output:

  • Output a single integer: the absolute difference between the sums of the primary and secondary diagonals.

Example:

Input:

3
11 2 4
4 5 6
10 8 -12

Output:

15

Explanation:

  • The primary diagonal elements are: 11, 5, -12. Sum = 4.
  • The secondary diagonal elements are: 4, 5, 10. Sum = 19.
  • The absolute difference between the sums is |4 - 19| = 15.

This explanation should make it clear what the problem is about and how to solve it. Add this description as comments at the top of your solution file (diagonal-difference.py), or include it in the pull request description. Here's how the comments could look:

# Problem: Diagonal Difference
# Description:
# Given a square matrix, calculate the absolute difference between the sums of its diagonals.
#
# Input:
# - The first line contains an integer n, the number of rows and columns.
# - The next n lines each contain n space-separated integers representing the matrix.
#
# Output:
# - Output a single integer, the absolute difference between the sums of the primary and secondary diagonals.
#
# Example:
# Input:
# 3
# 11 2 4
# 4 5 6
# 10 8 -12
# Output:
# 15

Copy link

welcome bot commented Oct 19, 2024

I can tell this is your first pull request! Thank you I'm so honored. 🎉🎉🎉
I'll take a look at it ASAP!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant