Maximum Points from Cards — C# Coding Problem
Difficulty: medium | Category: sliding-window
Problem Description
There are several cards arranged in a row, and each card has an associated number of points. The points are given in the integer array `cardPoints`. In one step, you can take one card from the beginning or from the end of the row. You have to take exactly `k` cards. Return the **maximum** score you can obtain. **Insight:** Taking `k` cards from both ends is equivalent to leaving a contiguous window of `n - k` cards in the middle. Minimize the window sum → maximize the total.
Examples
Example 1
Input: cardPoints = [1,2,3,4,5,6,1], k = 3
Output: 12
Explanation: Take the three cards on the right: 1+6+5=12.
Example 2
Input: cardPoints = [9,7,7,9,7,7,9], k = 7
Output: 55