Hi Leetcoders,
I would like to share a problem from past LG coding challenge test. They use lengthy problem description, so I rephrase the problem as below:
Given an array of N<150000 size, each item with value 0<P<500. We want to make multiple jumps over the value at certain indexes in the array so that:
For each jump:
- even jump (jumpCounter = even) will add value equal to
P[i] where i is the index in the array
- odd jump (jumpCounter = odd) will decrease equal to
P[i] where i is the index in the array
- find the total value such that it goes maximum.
- there is no minimum constrain on the number of jump, but its max is N.
Example: P = [7,2,1,8,4,3,5,6]
Make 8 jumps => total value = 7-2+1-8+4-3+5-6=-2
Make only 5 jumps => total value = 7-1+8-3+6=17 (note that the value of array[i] in odd jump should be selected to minize the creasing value)
Make only 3 jumps => total value = 7-1+8 = 16
Thus making 5 jump with value = 17 is the max achievable. Neither making too many jumps or too few jump would help.