• + 1 comment

    Could you explain the code please? I got up to here but I dont take into account g games so not sure what Im missing as I pass the first test case but fail others.

    def twoStacks(maxSum, a, b): score = 0 counter = 0

    while score < maxSum:
        head_a = a[0]
        head_b = b[0]
        if head_a > head_b and (score + head_b < maxSum):
            score += head_b
            b.pop(0)
        elif head_b > head_a and (score + head_a < maxSum):
            score += head_a
            a.pop(0)
        else:
            break
        counter += 1
    return counter