Tap here to switch tabs
Problem
Submissions

Problem: Coin Path

med
30 min
Try to solve the Coin Path problem.

Statement

You are given an integer array coins and an integer maxJump.

You start at index 11 and want to reach index coins.length. From any index ii, you are allowed to jump to any index jj such that i<j≤i+i < j \leq i + maxJump and coins[j] ≠−1\neq -1. The cost of jumping to index jj is coins[j] coins.

Return the path of 11 based indices from index 11 to index coins.length that incurs the minimum total cost. If there are multiple paths with the same minimum cost, return the lexicographically smallest path. If it is impossible to reach the final index, return an empty array.

Constraints:

  • 1≤1 \leq coins.length ≤1000\leq 1000

  • −1≤-1 \leq coins[i] ≤100\leq 100

  • coins[1] ≠−1\neq -1

  • 1≤1 \leq maxJump ≤100\leq 100

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Coin Path

med
30 min
Try to solve the Coin Path problem.

Statement

You are given an integer array coins and an integer maxJump.

You start at index 11 and want to reach index coins.length. From any index ii, you are allowed to jump to any index jj such that i<j≤i+i < j \leq i + maxJump and coins[j] ≠−1\neq -1. The cost of jumping to index jj is coins[j] coins.

Return the path of 11 based indices from index 11 to index coins.length that incurs the minimum total cost. If there are multiple paths with the same minimum cost, return the lexicographically smallest path. If it is impossible to reach the final index, return an empty array.

Constraints:

  • 1≤1 \leq coins.length ≤1000\leq 1000

  • −1≤-1 \leq coins[i] ≤100\leq 100

  • coins[1] ≠−1\neq -1

  • 1≤1 \leq maxJump ≤100\leq 100