Maximum non-adjacent task value
You are given a list of integers, each the net value of an optional task; values may be negative. You may complete any subset of the tasks, with one restriction: you can never complete two tasks that sit at adjacent positions in the list. Completing no tasks at all is allowed and scores 0. Return the maximum total value you can achieve. For example, [3, -2, 5] gives 8 by taking positions 0 and 2.
Implement
best_task_total(values: list[int]) → intExamples
in
[[3,-2,5]]out8in
[[-4,-1,-7]]out0What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 10 min
solution.py
InputExpectedGot
[[3,-2,5]]8not run yetsample[[-4,-1,-7]]0not run yetsample