Your free access ends in 7 days — and you haven’t tried it yet. Watch one algorithm run, start to finish. It takes about two minutes.

Try one problem
0
Problem

Max Points From Cards

LeetCode #1423Medium
Take K from either end · complement window

Given a row of cards with point values, take exactly k cards from either the start or the end, and return the maximum total points obtainable.

Asked atAmazonGoogle
step 1 / 22
11
4
2
3
9
1
12
[0][1][2][3][4][5][6]
Brute force · try every front/back split
1given cards, K
2best ← 0
3for t ← 0 to K:
4 score = sum(front t) + sum(back K − t)
5 best = max(best, score)
6return best
state
  • n7
  • K3
  • total42

line 1Take exactly K = 3 cards, each from the FRONT or the BACK of the row. Maximize the points you take. (You can mix ends.)