You are viewing a single comment's thread. Return to all comments →
Here is my solution #swift
func hourglassSum(arr: [[Int]]) -> Int { var maxAry = [Int]() for i in 0..<4 { for j in 0..<4 { let top = arr[i][j...(j+2)].reduce(0,+) let middle = arr[i+1][j+1] let bottom = arr[i+2][j...(j+2)].reduce(0,+) let total = top + middle + bottom maxAry.append(total) } } print(arr) return maxAry.max() ?? 0 }
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 is my solution #swift