0

Example -

Let's say array is {3, -1, 8, 12, 10} then it should return 1 as array elements {3, -1, 10} sums upto max element which is 12

So conditions are -

  1. Array elements that sums up to max. element need not to be continuous.
  2. Array is not sorted
  3. It contains negative numbers

I can do it in brute force way but I am pretty sure there exists a more efficient solution, possibly O(N) solution.

  • 1
    This is known as the [subset sum problem](https://en.wikipedia.org/wiki/Subset_sum_problem) and does not have a subexponential solution unless the array elements are all small. See [this post](https://stackoverflow.com/q/4355955/16757174) or the subset-sum tag for more information. – kcsquared Feb 07 '22 at 20:25

0 Answers0