cards lies on the table. Two players take turns, and the first player starts. On a turn a player takes one card from either end of the row, the leftmost or the rightmost, and adds its number to their score. The game ends when no cards are left.
Both play optimally. Return True if the first player ends with at least as many points as the second (a tie also counts as a win for them), and False otherwise.cards=[3, 9, 1, 2] → True
The first player takes 2. The second is left with 3 and 1 at the ends; whichever they take, the first player grabs 9. The first player ends with at least 11, the second with at most 4.
cards=[2, 7, 3] → False
Whichever end the first player takes, the second grabs 7. The first player gets 2 + 3 = 5 < 7.
cards=[4, 4] → True
cards) ≤ 20cards[i] ≤ 10⁷cards=[3, 9, 1, 2]
True
Run checks the first 3 tests in your browser. Submit checks all 112 tests on the server, hidden ones included.