An array of costs was given. You can either take two jumps forward or one jump backward. If you land on a particular index, you have to add the cost to your total. Find the minimum cost needed to cross the array or reach the end of the array.
Input:
5 (Number of elements in the array)
[9,4,6,8,5] (Array)
1 (Index to start)
Output:
12
Explanation: We start from index 1, jump to 3 and then jump out for a total cost of 8+4=12.
How can we build the DP solution for this?