You are viewing a single comment's thread. Return to all comments →
Swift: easy to read O(n)
func diagonalDifference(arr: [[Int]]) -> Int { // Write your code here let length = arr.count var leftDiagnolSum = 0 var rightDiagnolSum = 0
for i in (0..<length) { leftDiagnolSum += arr[i][i] rightDiagnolSum += arr[(length - 1) - i][i] } let difference = leftDiagnolSum - rightDiagnolSum return difference >= 0 ? difference : difference * -1
}
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Diagonal Difference
You are viewing a single comment's thread. Return to all comments →
Swift: easy to read O(n)
func diagonalDifference(arr: [[Int]]) -> Int { // Write your code here let length = arr.count var leftDiagnolSum = 0 var rightDiagnolSum = 0
}