cards. Alice and Bob take turns, Alice first. On a turn, a player takes one, two or three cards from the front of the row and adds their numbers to their score. The game ends when no cards remain; both start with 0 points.
Both play optimally, each trying to finish ahead of the other. Return "Alice" if Alice wins, "Bob" if Bob wins, and "Tie" if their scores are equal.cards=[4, -2, 5, 1] → 'Alice'
Alice takes three cards (4 − 2 + 5 = 7) and leaves Bob with 1. She cannot do better, and Bob cannot stop her.
cards=[-3, 6, 2, 1] → 'Alice'
However Alice starts, she has to take the −3. Taking the first three cards gives her 5 and Bob gets 1, so she wins: the answer is Alice.
cards=[5, -1, -1, 9] → 'Bob'
However many cards Alice takes, Bob takes the rest, the 9 included: 5 against 7, 4 against 8, or 3 against 9. Bob wins.
cards=[4, -2, 5, 1]
'Alice'
Run checks the first 3 tests in your browser. Submit checks all 103 tests on the server, hidden ones included.