Tap here to switch tabs
Problem
Submissions

Problem: Maximum Points You Can Obtain from Cards

med
30 min
Try to solve the Maximum Points You Can Obtain from Cards problem.

Statement

You are given an integer array cardPoints, where each element represents the points on a card in a row. You must take exactly k cards. On each move, you may take one card from either the beginning or the end of cardPoints.

Return the maximum total points you can obtain after taking exactly k cards.

Constraints:

  • 1≤1 \leq cardPoints.length ≤105\leq 10^5

  • 1≤1 \leq cardPoints[i] ≤104\leq 10^4

  • 1≤1 \leq k ≤\leq cardPoints.length

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Maximum Points You Can Obtain from Cards

med
30 min
Try to solve the Maximum Points You Can Obtain from Cards problem.

Statement

You are given an integer array cardPoints, where each element represents the points on a card in a row. You must take exactly k cards. On each move, you may take one card from either the beginning or the end of cardPoints.

Return the maximum total points you can obtain after taking exactly k cards.

Constraints:

  • 1≤1 \leq cardPoints.length ≤105\leq 10^5

  • 1≤1 \leq cardPoints[i] ≤104\leq 10^4

  • 1≤1 \leq k ≤\leq cardPoints.length