Last active
March 10, 2022 17:15
-
-
Save onedayitwillmake/34fec35672c73598714333f5f0c6d527 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def preprocess(A): | |
return A | |
def solution(mat, i, j, m, n): | |
# write your solution here | |
sum1 = 0 | |
for ix in range(len(mat)): | |
row = mat[ix] | |
for jx in range(len(mat)): | |
column = row[jx] | |
if (i <= ix < i + n) and (j <= jx < j + m): | |
sum1 += column | |
print(f"Adding {column} from ({ix},{jx}) to sum. Sum = {sum1}") | |
return sum1 | |
# test run 1 | |
A = [[2, 8, 3, 2, 7], | |
[10, 6, 4, 8, 3], | |
[2, 7, 3, 7, 8], | |
[8, 5, 10, 9, 2], | |
[2, 6, 10, 4, 9]] | |
mat = preprocess(A) | |
assert 22 == solution(mat, 1, 2, 2, 2) # should be 22 | |
print("") # space | |
# query1 | |
assert 27 == solution(mat, 0, 2, 3, 2) # should be 27 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment