Maximum Points You Can Obtain from Cards Problem
Maximum Points You Can Obtain from Cards Problem — ExecCode Easy DSA Practice
Solve the Maximum Points You Can Obtain from Cards problem on ExecCode. Free online easy DSA practice in Sliding Window. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Description You have to take exactly k cards. Your task is to given the integer array cardPoints and the integer k, return the maximum score you can obtain. 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. Your score is the sum of the points of the cards you have taken.
Examples
Input {"nums": [1, 79, 80, 1, 1, 1, 200, 1], "k": 3}; Output 202
Constraints
1 <= cardPoints.length <= 10^5 1 <= cardPoints[i] <= 10^4 1 <= k <= cardPoints.length
Practice Maximum Points You Can Obtain from Cards free on ExecCode. Browse DSA problems, topic map, and placement guides.