costs = List.of(2, 5, 8), then:
n, where n is the number of elements, orn, which means you have crossed the arrayint minimumCost(List<Integer> costs)
costs is a list of positive integerscosts.get(0) represents the cost at index 1costs.get(i) represents the cost at index i + 1n or cross beyond it11 adds its cost immediatelyi, you may move only to:
i + 2i - 1n, no additional cost is added for that move1 ≤ costs.size() ≤ 100,0001 ≤ costs.get(i) ≤ 10,000minimumCost(costs = List.of(2, 5, 8))101, pay 23, pay 82 + 8 = 10minimumCost(costs = List.of(4))41minimumCost(costs = List.of(3, 100, 2, 1))51, pay 33, pay 25, which crosses the array3 + 2 = 5minimumCost(costs = List.of(5, 1, 7, 1, 1))131, pay 53, pay 75, pay 15 + 7 + 1 = 13minimumCost(costs = List.of(1000000, 1, 1000000, 1, 1000000, 1))20000031, pay 10000003, pay 10000002, pay 14, pay 16, pay 11000000 + 1000000 + 1 + 1 + 1 = 2000003