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.
# Enter your code here. Read input from STDIN. Print output to STDOUTmaxsum=[0]defmax_sum(t,l,i,lsum):m,n=i,i+1ifl==len(t)-1:maxsum[0]=max(maxsum[0],lsum+t[l][m],lsum+t[l][n])returnmax_sum(t,l+1,m,lsum+t[l][m])max_sum(t,l+1,n,lsum+t[l][n])for_inrange(int(input())):triangle,lvl,maxsum[0]=[],int(input()),0foriinrange(lvl):triangle.append(list(map(int,input().split())))#print(triangle)iflvl>1:max_sum(triangle,1,0,triangle[0][0])print(max(maxsum[0],triangle[0][0]))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #18: Maximum path sum I
You are viewing a single comment's thread. Return to all comments →