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.
you can avoid writing the long sequence of additions the following way:
1) create a variable called total equal to arr[i+1][j+1]
2) create a third loop of k in range(3).
3) On each iteration of k, add arr[i][j+k] and arr[i+2][j+k] to total.
4) append total to k
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 →
you can avoid writing the long sequence of additions the following way:
1) create a variable called total equal to arr[i+1][j+1]
2) create a third loop of k in range(3). 3) On each iteration of k, add arr[i][j+k] and arr[i+2][j+k] to total. 4) append total to k