values. While the array has at least two elements you may make a move by deleting one of these pairs:
- the first two elements;
- the last two elements;
- the first and the last element.
The sum of the deleted pair is the cost of the move. All the moves you make must have the same cost.
Return the largest number of moves you can make under this rule.values=[3, 4, 2, 5, 1, 6] → 3
Remove the first two (3 + 4 = 7), then the first two again (2 + 5 = 7), then the remaining 1 and 6 (7 as well). Three moves.
values=[5, 1, 8, 2, 4] → 2
Starting with 5 + 4 = 9, the next move takes 1 + 8 = 9 and a single number is left. The other first moves (cost 6) also allow at most two moves.
values=[7, 7] → 1
The only possible move removes both numbers.
values=[3, 4, 2, 5, 1, 6]
3
Run checks the first 3 tests in your browser. Submit checks all 117 tests on the server, hidden ones included.