Solving Questions With Brainpower
Real-world version: Choosing Which Tasks to TakeThe statement here is our own: the same inputs, outputs and technique.
A shift offers tasks in a fixed order, given as tasks, where tasks[i] = [points, rest].
Work through the tasks from the first to the last. At each task you may either take it, earning its points and then skipping the next rest tasks entirely, or leave it and move straight on to the next.
Return the most points the shift can earn.
Examples
Example 1
- Input
- tasks = [[1, 5], [9, 1], [1, 1]]
- Output
- 9
Leaving the first task and taking the second earns nine, which beats taking the first for one and then being skipped past everything else.
Example 2
- Input
- tasks = [[5, 1], [5, 1], [5, 1]]
- Output
- 10
Each task skips the one after it, so the first and the third can both be taken, earning ten.
Example 3
- Input
- tasks = [[10, 1]]
- Output
- 10
One task, so take it: the rest period runs off the end of the shift and costs nothing.
Constraints
- 1 <= tasks.length <= 10^5
- tasks[i].length == 2
- 1 <= tasks[i][0] <= 10^5
- 1 <= tasks[i][1] <= 10^5
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def most_points(tasks: list[list[int]]) -> int:public long mostPoints(int[][] tasks)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 15 test cases: 15 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's