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.
In Python, key is to import inf first so cases with only negative numbers pass:
#!/bin/python3importmathimportosimportrandomimportreimportsysfrommathimportinf## Complete the 'hourglassSum' function below.## The function is expected to return an INTEGER.# The function accepts 2D_INTEGER_ARRAY arr as parameter.#defhourglassSum(arr):curm=-infforiinrange(0,4):forjinrange(0,4):l=(arr[i][j]+arr[i][j+1]+arr[i][j+2]+arr[i+1][j+1]+arr[i+2][j]+arr[i+2][j+1]+arr[i+2][j+2])curm=max(curm,l)returncurmif__name__=='__main__':fptr=open(os.environ['OUTPUT_PATH'],'w')arr=[]for_inrange(6):arr.append(list(map(int,input().rstrip().split())))result=hourglassSum(arr)fptr.write(str(result)+'\n')fptr.close()
Cookie support is required to access HackerRank
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
2D Array - DS
You are viewing a single comment's thread. Return to all comments →
In Python, key is to import inf first so cases with only negative numbers pass: