We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
This code uses list comprehension to build a list of hour glass sums. For the rows where 3 values are added, I used sum(arr[row][col:col+3]) then summed all values. The code starts at i, j = 0, 0 and I used the size of the array to limit the i and j terms. Think nested loop
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
2D Array - DS
You are viewing a single comment's thread. Return to all comments →
Here's a python3 one-liner.
This code uses list comprehension to build a list of hour glass sums. For the rows where 3 values are added, I used
sum(arr[row][col:col+3])
then summed all values. The code starts at i, j = 0, 0 and I used the size of the array to limit the i and j terms. Think nested loop