Diagonal Difference | Solving Hackerrank with python | Ep5

preview_player
Показать описание
Here we are with the fifth episode of Solving #Hackerrank with Python series where we will explain and solve #Diagonal_Difference using #python.

timestamps
[00:00] Intro
[00:33] What is Diagonal Difference?
[00:50] Solving Diagonal Difference with math.
[04:00] Let's Write Code.

~~~~~~~~~~~~~
About The Channel :

#Whilelab is a channel that focus on the software side of things here we you will find videos explaining software or top tips on other software and of course programming videos and courses.

~~~~~~~~~~~~~
Subscribe for free from this link:
~~~~~~~~~~~~~

Playlists I think you would like to watch :

~~~~~~~~~~~~
Social Media Account

Рекомендации по теме
Комментарии
Автор

Why you stop solving hacker rank problems, you explained in how to approach a problem without directly to the solution great way please explain all the questions it will help to crack

roopkummar
Автор

What would you suggest to get better with arrays like that used in counter2? I had a hard time making that connection with the array length. I would have thought the array length would be 9 and not 3.

Redd
Автор

Thanks for your videos! Here's my function:

def diagonalDifference(arr):
# Write your code here
left_diagonal = []
right_diagonal = []
#print(len(arr))
for i in range(len(arr)):

#print(left_diagonal)
for i in range(len(arr)-1, -1, -1):

#print(right_diagonal)
ldiag_sum=sum(left_diagonal)
rdiag_sum=sum(right_diagonal)
diff = ldiag_sum-rdiag_sum
return abs(diff)

tanercoder
Автор

damm ... you have fantastic explanation skills. which is rare for programmers. good job man :) keep uploading hackerrank videos man

qc
Автор

I love the challenge in this problem. thanx

modaryaghi
Автор

Found a much simpler yet less intuitive solution via stack overflow:
difference = sum(row[i] - row[-i-1] for i, row in enumerate(arr))
return abs(difference)

Can't seem to understand it yet, but it works.

chanhuangsuan
Автор

Listen to me, you are a fucking amazing person the most bad ass that I've ever seen, i tried to figure out by my own and i couldn't solve, then i went to discussions and saw the answer, but i didn't understand why it was the answer and you basically explained very well so i wish you to be happy with health and money!!!

electricimpulsetoprogramming
Автор

def diagonalDifference(arr):
# pd => Primary Diagonal && sd => Secondary Diagonal
pd = 0
sd = 0
j = 0
k = len(arr) - 1
for i in range(len(arr)):
pd += arr[i][j]
sd += arr[i][k]
k -= 1
j += 1

return abs(pd - sd)


Hi, here are other solution for this challenge, in this algorithm I use one only for loop
Sorry my English is not my native language

royerguerrerop
Автор

I didnt understand (n-i-1) but you clarify. Thank you

DaniLo
Автор

Hi !! I trie doing the same coding today and 9/11 test cases failed Can I somehow send u the code so that you could have a look and tell me where am I wrong as I cant seem to debug it :(

riashrivastava
Автор

I did like that :

first_diag = arr[0][0] + arr[1][1] + arr[2][2]
sec_diag = arr[0][2] + arr[1][1] + arr[2][0]
return abs(first_diag - sec_diag)

sefabockun
Автор

lets try this asked question in company, help me to solve this by making video:


From an N * N sized matrix, compute the smallest elements from the
two diagonals, and output the multiplication of these two smallest
numbers

technoinfoworldwide
Автор

my second counter isn't working when following along

benjamindiaz
visit shbcf.ru