in above case we need to do some checking like in case when next element is 10;
next elements is 10 10-4 = 6 , 6 > 4 add(1,3,4 ) = 8 8 < 10(required_element) , so add 1 to 8 = 9 and do same as mentioned but if sum( number_found_so_far ) > required_num then add 1 to difference of required_num - least number . for example :- suppose in the same example if i add 15 in the end of given input now next elem 15 - 4 = 11 sum(1,3,4,9) = 17 15 < 17 , so add 1 to 11 = 12 and use this number(i.e 12 ) and element_found_so_far(i.e 1,3,4,9) to form 15 ( 12 + 3 ) : yes , so 12 should be there On Tue, Dec 13, 2011 at 11:51 PM, atul anand <[email protected]>wrote: > i am not sure , but this came to me when i first read it > > here is the idea:- > given : 4 5 7 10 12 13 > > 4 should be there boz it is the least. > > next is 5 , 5-4 =1 which is less that 4 , so 1 should be there > > next is 7 , 7-4 = 3 which is less than 4 , so 3 should be there > > next is 10 , 10-4 = 6 which is greater then 4 , so add previous found > elements > i.e 1,3,4 add them 1+3+4 = 8 , add 1 to 8 = 9 > > now check ,can we use this number(i.e 9 ) and previous found elements ( > 1,3,4) to > form 10 ( 9 +1) : yes -> so 9 should be there > > next is 12 , 12-4 = 8 ( but now greatest element among 1,3,4,9 is 9) and 8 > < 9 ,so skip; > > next is 13 , 13-4 = 9 same reason for skipping as for number 12 before. > > > > On Tue, Dec 13, 2011 at 10:28 PM, top coder <[email protected]> wrote: > >> If pairwise sums of 'n' numbers are given in non-decreasing order >> identify the individual numbers. If the sum is corrupted print -1 >> Example: >> i/p: >> 4 >> 4 5 7 10 12 13 >> >> o/p: >> 1 3 4 9 >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to [email protected]. >> To unsubscribe from this group, send email to >> [email protected]. >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> >> > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
