11
4
2
3
9
1
12
[0][1][2][3][4][5][6]
Brute force · try every front/back split
▸1given cards, K2best ← 03for t ← 0 to K:4 score = sum(front t) + sum(back K − t)5 best = max(best, score)6return best
state
- n7
- K3
- total42
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 problemGiven 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.
▸1given cards, K2best ← 03for t ← 0 to K:4 score = sum(front t) + sum(back K − t)5 best = max(best, score)6return best
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.)