Problem · Array
Minimum Jump Cost
Learn this problemProblem statement
There are n points on the x-axis at coordinates 1, 2, 3, ..., n. The i-th point has an associated cost cost[i].
Starting from coordinate x = 0, you can make jumps of length at most k. Whenever you stop at a point, you incur the cost of that point.
Find the minimum total cost required to reach point n.
Function
getMinimumCost(cost: int[], k: int) → longExamples
Example 1
cost = [4,3,9,3,1]k = 2return = 7The optimal jump pattern is 0 -> 2 -> 4 -> 5. The cost of stopping at points 2, 4, and 5 is 3 + 3 + 1 = 7, which is the minimum possible.
Example 2
cost = [1,2,3,4]k = 2return = 6The optimal path is 0 -> 2 -> 4, with total cost 2 + 4 = 6.
Constraints
1 <= n <= 3 * 10^51 <= k <= n1 <= cost[i] <= 10^9
More Microsoft problems
- Maximum Score with Prime JumpsOA · Seen Aug 2026
- Authentication SystemOA · Seen Jul 2026
- Binary String Swap TimeOA · Seen Jul 2026
- Minimum Effort Task ScheduleOA · Seen Jul 2026
- Maximum Pipeline ThroughputOA · Seen Jul 2026
- Maximum Strong Team SubarrayOA · Seen Jul 2026
- Minimum Cost K-Capable ModelsOA · Seen Jul 2026
- Alphabetically Smallest PalindromeOA · Seen Jul 2026