You are viewing a single comment's thread. Return to all comments →
def twoStacks(maxSum, a, b): Totalsum = 0 countS1 = 0 countS2 = 0 result = 0 for ele in a: if Totalsum + ele > maxSum: break Totalsum = Totalsum + ele countS1 = countS1 + 1 for ele in b: Totalsum = Totalsum + ele countS2 = countS2 + 1 while Totalsum > maxSum and countS1 > 0: Totalsum = Totalsum - a[countS1-1] countS1 = countS1 -1 if Totalsum <= maxSum: result = max((countS1 + countS2), result) return result
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
Game of Two Stacks
You are viewing a single comment's thread. Return to all comments →