Solving Questions With Brainpower

You are given a 0-indexed 2D integer array questions where questions[i] = [points_i, brainpower_i].

The array describes the questions of an exam, where you have to process the questions in order starting from question 0 and decide whether to solve or skip each question.

  • Solving question i will earn you points_i points, but you will be unable to solve each of the next brainpower_i questions.
  • If you skip question i, you get to make the decision on the next question.

Return the maximum points you can earn for the exam.

Example 1
Inputquestions = [[3,2],[4,3],[4,4],[2,5]]
Output5
The maximum points can be earned by solving questions 0 and 3 for a total of 3 + 2 = 5 points, and there is no way to earn 5 or more points otherwise.
Example 2
Inputquestions = [[1,1],[2,2],[3,3],[4,4],[5,5]]
Output7
The maximum points can be earned by skipping question 0, solving question 1, then solving question 4 for a total of 2 + 5 = 7 points.

Constraints

  • 1 <= questions.length <= 10^5
  • questions[i].length == 2
  • 1 <= pointsi, brainpoweri <= 10^5

Asked at 5 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate