Choose which questions to solve to maximize points, but each solved question forces you to skip some following questions.
Problem
You are given a list of questions. Each question has two values: the points you earn by solving it and the number of next questions you must skip if you solve it.
Starting from the first question, you may either:
- solve the current question and earn its points, then move forward by the required skip count, or
- skip the current question and move to the next one.
Return the maximum total points you can earn.
Notes
- The questions are processed in order.
- If you solve question
i, then the next question you may consider isi + brainpower[i] + 1. - You may skip any number of questions.
Input Format
- A 2D array
questions, wherequestions[i] = [points, brainpower].
Output Format
- Return an integer representing the maximum achievable score.
Input Format
questions: an array of pairs[points, brainpower]pointsis the score for solving the questionbrainpoweris the number of following questions to skip after solving it
Output Format
- Return the maximum total points obtainable by choosing an optimal subset of questions.
Constraints
1 <= questions.length- Each question contributes either by being solved once or skipped
- A solved question forces skipping a contiguous block of following questions
- Use 64-bit integer logic if the cumulative score can exceed 32-bit range
Example 1
Input
questions = [[3,2],[4,3],[4,4],[2,5]]
Output
5
Explanation
Solve question 0 for 3 points, then skip questions 1 and 2, and solve question 3 for 2 more points. Total = 5.
Example 2
Input
questions = [[1,1],[2,2],[3,3],[4,4],[5,5]]
Output
7
Explanation
One optimal choice is to solve questions 0, 2, and 4 for a total of 1 + 3 + 5 = 9? Not possible because solving 0 skips 1, solving 2 skips 3, and solving 4 is allowed. The correct optimal path is solve 1 and 4 for 2 + 5 = 7.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.