You are viewing a single comment's thread. Return to all comments →
A solution in Python that respects the constraints proposed by the challenge (and focuses on readability):
""" Constraints: -9 <= arr[i][j] <= 9 0 <= i,j <= 5 """ def get_hour_glass_sum(arr: List[int], x: int, y: int) -> int: first_line = sum([arr[x][y + i] for i in range(3)]) second_line = arr[x + 1][y + 1] third_line = sum([arr[x + 2][y + i] for i in range(3)]) return first_line + second_line + third_line def hourglassSum(arr): greater_sum = None for x in range(4): for y in range(4): current_sum = get_hour_glass_sum(arr, x, y) if greater_sum is None: greater_sum = current_sum continue greater_sum = max(current_sum, greater_sum) return greater_sum
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 →
A solution in Python that respects the constraints proposed by the challenge (and focuses on readability):