Solving Questions With Brainpower

MediumDynamic Programming1d dp

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

An exam is given as a 0-indexed array questions where questions[i] = [points_i, brainpower_i]. You go through the questions strictly in order and, for each one, decide to **solve** it or **skip** it. Solving question i earns points_i, but you are then unable to solve the next brainpower_i questions (they are skipped automatically). Skipping a question costs nothing and lets you decide on the next one. Return the maximum total points you can earn. The total can exceed 32-bit range.

Examples

Input: questions = [[3,2],[4,3],[4,4],[2,5]]
Output: 5
Solve question 0 (3 points, skip 1 and 2), then solve question 3 (2 points).
Input: questions = [[1,1],[2,2],[3,3],[4,4],[5,5]]
Output: 7
Solve question 1 (2 points, skip 2 and 3), then question 4 (5 points).

Constraints

  • 1 <= questions.length <= 10^5
  • questions[i].length == 2
  • 1 <= points_i, brainpower_i <= 10^5

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More 1d dp problems