Implement a Coin-Constrained Jump Strategy
Company: Coinbase
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: hard
Interview Round: Take-home Project
Quick Answer: This question evaluates a candidate's ability to design a stateful decision-making strategy combining physics-based motion reasoning, resource-constrained planning, and collision/constraint handling.
Constraints
- 2 <= height <= 50
- 1 <= jump_power <= 10
- 1 <= position < height
- -height <= velocity <= height
- 0 <= coins <= 20
- 0 <= len(future_coins) <= 40
- Each value in future_coins is either -1 or an integer in the range [1, height - 1]
Examples
Input: (10, 3, 1, -1, 1, [-1])
Expected Output: True
Explanation: Without jumping, the character moves to position 0 and loses immediately. With a jump, it spends 1 coin, moves safely upward, and survives the only tick.
Input: (8, 4, 5, 0, 2, [-1, -1])
Expected Output: False
Explanation: Jumping now makes the character move to position 9, which is above the top boundary height = 8. Not jumping survives both ticks.
Input: (10, 3, 2, 0, 1, [5, -1, -1, -1])
Expected Output: True
Explanation: Jumping now reaches height 5 on the first tick, collects the coin, and still survives all 4 ticks. Not jumping can also survive all 4 ticks, but ends with fewer coins, so jumping is optimal.
Input: (10, 3, 5, 0, 2, [])
Expected Output: False
Explanation: There are no future ticks to optimize. Both actions are equivalent, so the strategy should avoid an unnecessary jump.
Input: (7, 3, 1, -1, 0, [3])
Expected Output: False
Explanation: The character has no coins, so a jump request has no effect. Both jump and no-jump lead to immediate loss, so return False on the tie.
Input: (9, 2, 3, 1, 1, [4, 4, -1])
Expected Output: False
Explanation: Not jumping collects the coin at height 4 on the first two ticks and survives all 3 ticks. Jumping now rises too high and cannot survive as long.
Hints
- A state is fully determined by the current tick index, position, velocity, and remaining coins. That suggests memoization or dynamic programming.
- Instead of storing just whether a state is winning, compare states with a tuple such as (survived_ticks, ending_coins, -successful_jumps_used).