Parition an array into different contiguous subarrays such that the sum of the differences between the largest and smallest element in each subarray is maximum.
Note: No limit on number of subarrays you can create
How would you solve this? I started with a brute force recursive approach and added some memoization, it worked but was TLE for some cases.
Eg:
The array[ 10, 6, 1, 3 ] can be partitoned into [ 10, 6, 1] and [3]
10 - 1 + 3-3 = 9