The smallest integer that cannot be represented by the sum of any subset of "A". E.g. if A = {1, 1, 1, 1}, output = 5; if A = {1, 2, 3, 4, 5}, output = 16 The simplest and possibly the worst method would be to find out all the subsets of A and store each"s sum in a Hash Map, then keep an integer i starting from 1 and check every time whether any sum equals to i.
Programming Concepts And Algorithms: Smallest Sum Not Present In An Array
No comments:
Post a Comment