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.
I feel like dp should be capable of helping. Just dont know how to implement. My code so far.
fromitertoolsimportcombinationsdefsolve(a,queries):n=len(a)dp=[]foriinrange(n):dp+=[[0]*n]#print(dp)foriinrange(n):forjinrange(n):ifi==j:dp[i][j]=a[j]elifj>i:dp[i][j]=max(a[i:j+1])#print(dp)l=[]forx,yinqueries:count=0ifx==y:print(dp[x-1][y-1])else:foriinrange(x-1,y):forjinrange(i,y):#print(i,j)count+=dp[i][j]print(count)#print(l)#return l
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Sum of the Maximums
You are viewing a single comment's thread. Return to all comments →
I feel like dp should be capable of helping. Just dont know how to implement. My code so far.