Problem
Cards are laid out in a row with values card_points. You take exactly k cards, one at a time, and each time you may take either the leftmost or the rightmost remaining card. Return the maximum total you can collect.
Example 1
- Input
- card_points = [1, 2, 3, 4, 5, 6, 1], k = 3
- Output
- 12
- Why
- take 1, 6, 5 from the right
Example 2
- Input
- card_points = [9, 7, 7, 9, 7, 7, 9], k = 7
- Output
- 55
- Why
- take everything
Constraints
1 <= card_points.length <= 10^51 <= card_points[i] <= 10^41 <= k <= card_points.length