Jump Game with Profit

Asked at Google

Reported by the problem's creator, not verified

You stand at index 0 of two parallel lists, jump and profit. At index i you either take it (collect profit[i] and move to i + 1 + jump[i]) or skip it (collect nothing and move to i + 1). The walk ends once your index is n or beyond, where n is the list length.

Examples

  1. Example 1

    Input: jump = [2,0,0,0], profit = [5,4,3,2]

    Output: 9

    Explanation: Taking index 0 earns 5 and lands on index 3, where taking earns 2, for 7. Skipping index 0 and taking indices 1, 2 and 3 earns 4 + 3 + 2 = 9, which is the best.

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.