We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
funchourglassSum(arr:[[Int]])->Int{// Write your code herevarmaxSum:Int?forrowIndexin1..<5{forelementIndexin1..<5{letupperRow=arr[rowIndex-1]letcurrentRow=arr[rowIndex]letlowerRow=arr[rowIndex+1]letsum=upperRow[elementIndex-1]+upperRow[elementIndex]+upperRow[elementIndex+1]+currentRow[elementIndex]+lowerRow[elementIndex-1]+lowerRow[elementIndex]+lowerRow[elementIndex+1]ifmaxSum==nil{maxSum=sum}elseifletmaxSumLocal=maxSum,maxSumLocal<sum{maxSum=sum}else{continue}}}returnmaxSum??0}
Cookie support is required to access HackerRank
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 →
Swift Solution :-