Company: Wayfair_28oct
Difficulty: medium
Minimum Cost Problem Description There are n points on the x-axis (1, 2, 3, ..., n ). The i th point (1-indexed) has a cost associated with it, which is given by cost[i-1] where cost is a 0-indexed array of length n . 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 cost to reach point n by taking jumps of length at most k . Examples Example 1: Input: n = 5, cost = [4, 3, 9, 3, 1], k = 2 Output: 7 Explanation: The optimal jump pattern is 0 -> 2 -> 4 -> 5. The cost of stopping at points 2, 4, and 5 is cost[1] + cost[3] + cost[4] = 3 + 3 + 1 = 7, which is the minimum possible. Example 2: Input: n = 4, cost = [3, 2, 3, 4], k = 2 Output: 6 Explanation: The optimal path is 0 -> 2 -> 4. The cost is cost[1] (for point 2) + cost[3] (for point 4) = 2 + 4 = 6. Example 3: Input: n = 5, cost = [1, 9, 2, 6, 1], k = 3 Output: 3 Explanation: The optimal path is 0 -> 3 -> 5. The cost is cost[2] (fo