Created
August 14, 2021 03:33
-
-
Save azurast/92f20bba5f8f9b369f7ebbb3e3dc143d to your computer and use it in GitHub Desktop.
2D Array - DS
This file contains hidden or 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
// Interview Preparation Kit > Arrays > 2D Array - DS | |
var arr = [[1, 1, 1, 0, 0, 0], [0, 1, 0, 0, 0, 0], [1, 1, 1, 0, 0, 0], [0, 0, 2, 4, 4, 0], [0, 0, 0, 2, 0, 0], [0, 0, 1, 2, 4, 0]] | |
var arrayOfSum : [Int] = [] | |
for row in 0..<arr.count { | |
if (row >= 0 && row <= 3) { | |
for col in 0..<arr.count { | |
if (col > 0 && col < 5) { | |
print ("row \(row) column \(col)") | |
let a = arr[row][col-1] | |
let b = arr[row][col] | |
let c = arr[row][col+1] | |
let d = arr[row+1][col] | |
let e = arr[row+2][col-1] | |
let f = arr[row+2][col] | |
let g = arr[row+2][col+1] | |
let sum = a + b + c + d + e + f + g | |
arrayOfSum.append(sum) | |
} | |
} | |
} | |
} | |
print("array of sum \(arrayOfSum)") | |
print("max = \(String(describing: arrayOfSum.max()))") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment