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.
def Solve_Prob(n,k,strm):
maxi = -1
for i in range(0,n-k+1):
pro = 1
for j in range(i,i+k):
pro = pro*int(strm[j])
if pro > maxi:
maxi = pro
answer = maxi
return answer
t = int(input())
for i in range(0,t):
n,k = list(map(int,input().split()))
m = input()
answer = Solve_Prob(n,k,m)
print(answer)
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #8: Largest product in a series
You are viewing a single comment's thread. Return to all comments →
All test cases passed:
def Solve_Prob(n,k,strm): maxi = -1 for i in range(0,n-k+1): pro = 1 for j in range(i,i+k): pro = pro*int(strm[j]) if pro > maxi: maxi = pro answer = maxi return answer
t = int(input()) for i in range(0,t): n,k = list(map(int,input().split())) m = input() answer = Solve_Prob(n,k,m) print(answer)