On 4/22/2012 11:18 PM, Chris Rebert wrote:
On Sun, Apr 22, 2012 at 7:55 PM, Terry Reedy<tjreedy@udel.edu> wrote:
On 4/22/2012 9:07 PM, Nestor wrote: <snip>
false. For example: if arr contains [4, 6, 23, 10, 1, 3] the output should print true because 4 + 6 + 10 + 3 = 23.
Since the order of the numbers is arbitrary and irrelevant to the problem, it should be formulated in term of a set of numbers.
Er, multiplicity still matters, so it should be a multiset/bag. One possible representation thereof would be a list...
Er, yes. Given the examples, I (too quickly) misread 'will not contain all the same elements' as 'no duplicates'. In any case, a set was needed
And doesn't ordering matter too (for efficiency). A sorted list of the positive integers may solve in much less less time, right?