How to find the maximum sum of elements of a list with a given minimum distance between them

I have been looking for a way to find the possible combinations of a list, given a minimal distance of 3 between all the numbers.

Suppose we have

list = [23, 48, 10, 55, 238, 11, 12, 23, 48, 10, 55, 238, 11, 12, 23, 48, 10, 55, 238, 11]

The best possible combination would be 23 + 238 + 238 + 238 = 737.

I've tried parsing the list and selecting each time the max of the split list[i:i+4], like so :

23 -skip three indexes -> max of [238, 11, 12, 23] : 238 -skip three indexes -> max of [48, 10, 55, 238] : 238 skip three indexes -> max of [48, 10, 55, 238] : 238

This worked with this case, but not with other lists where I couldn't compare the skipped indexes.

Any help would be greatly appreciated.



Comments

Popular posts from this blog

Spring Elasticsearch Operations

Object oriented programming concepts (OOPs)

Network Error and Timeout on Authorize.net JS