# Solving Questions with Brainpower

## Transitions

For question `i`

, either:

Solve the question, gain the points, and only be able to answer the

`i + cooldown`

problem onwardsSkip the question

## Top-down

The recurrence relation, much like other Linear Sequence problems is obtained by directly mapping the transitions.

## Bottom-up

The recurrence is the same as the top-down approach as we need to have information about the "next" state, so prefixes will not be an ideal solution for this.

This means we will have to iterate from the back. We also add a padding of `0`

towards the end of the array to represent the case when `i + 1`

or `i + questions[i][1] + 1`

exceed `N`

(length of questions).

**Trick: **Boundary conditions
Very often you will encounter state transitions that can cause out of bounds such as `i + 1 >= N`

above. In these scenarios, you can introduction boundary conditions by modifying the `dp`

array to include additional leading/trailing elements.
If the state transition may go *very* out of bounds like `i + questions[i][1] + 1`

, then you can use `min(transition, N)`

to default it to use the boundary condition.
The value of the boundary condition is often the case when there is nothing to process. In this case, we add `0`

as that's the default value that exists when there's "no questions".

## Further discussion

Actually, there is a way to implement the bottom-up solution using the "re-framing the problem" trick.

Given that we want to solve question

`i`

, what's the maximum points achievable?

By thinking of the problem this way, we can devise an approach to figure out how to forcibly "solve" question `i`

. We can iterate through `0..i-1`

to find all days where we would have solved it and the cooldown does not exceed `i`

. This results in the following recurrence instead:

However, I would like to bring this up as an alternative thought process to highlight how sometimes "re-framing" the problem might not always be the optimal solution.

Last updated