Standard Bar Sliding Window · Medium Problems O(n) · O(1)
A dispatch console shows a row of task cards, each carrying a completion score. An operator must claim exactly k cards but may only take from the two ends of the row. Because the claimed cards always form one prefix glued to one suffix, the unclaimed middle is a single contiguous block — and minimizing that block's score maximizes the haul.
Input: An integer array cardPoints and an integer k, the number of cards to claim.
Output: Return the maximum total score obtainable by claiming k cards from the row's ends.
1 <= cardPoints.length <= 10^51 <= k <= cardPoints.length1 <= cardPoints[i] <= 10^4Input: {"cardPoints":[1,2,3,4,5,6,1],"k":3}
Output: 12
Claiming 1+6+5 from the ends beats any other split of three picks.
Input: {"cardPoints":[2,2,2],"k":2}
Output: 4
All cards score alike, so any two picks yield the same total.