Take 1, 2, or 3 from the Front — Who Wins
Two engineers alternately claim work items from the front of a shared queue, taking 1, 2, or 3 items each turn and banking their point values. Both play optimally to maximize their own total.
Problem
Given an integer array values representing items in a row, two players alternate turns (the first player goes first). On each turn a player takes the first 1, 2, or 3 remaining items and adds their sum to their score. Both play optimally. Return "First", "Second", or "Tie" based on who ends with the higher score.
Input
An integer array values (item point values, may be negative).
Output
A string: "First", "Second", or "Tie".
Constraints
- 1 <= values.length <= 100000
- -1000 <= values[i] <= 1000
Examples
Example 1
Input
values = [1,2,3,7]
Output
Second
Whatever the first player takes, the second can secure a higher total.
Example 2
Input
values = [1,2,3,-9]
Output
First
Taking all of 1,2,3 leaves -9 for the opponent.