Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • 1
    One approach to solve this (in general) is to build a heap where the nodes store (1) an index for each list, (2) the list that was last incremented. The children have one index incremented, which is at least the (2) value (so we can't increment B then A). When the values are all small, you can probably get away with counting the groups that sum to (e.g.) 15, 14, 13, etc. Commented Nov 12, 2012 at 13:18
  • I would've suggested Evgeny Kluev's answer but I think you can do this in O(n) using a dynamic programming approach. You can google the solution to it. (e.g. dynamic programming largest sum of elements of array -- or something like that) Commented Nov 12, 2012 at 14:52
  • 1
    @PotatoQueue - my answer gives a solution using dynamic programming (at least that is the category of it as I remember from university). It is O(N), where N is the total number of values in the 4 lists. Commented Nov 12, 2012 at 15:48