• + 0 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