By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,960 Members | 990 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,960 IT Pros & Developers. It's quick & easy.

sum in an array

P: 1
Hi everyone,
can nyone tell me an algorithm other than bruteforce for this problem ?

S contains the set of positive integers. Find the largest number c such that c = a+b, where a, b, c are distinct
numbers of the set. If no c such exists, you should print “No Output”.
Sample Input:
2
7
1 6 10 3 14 18 51
6
7 3 1 9 4 5
Sample Output:
No Output
9 4 5.
Aug 5 '07 #1
Share this Question
Share on Google+
1 Reply


Expert 10K+
P: 11,448
Hi everyone,
can nyone tell me an algorithm other than bruteforce for this problem ?

S contains the set of positive integers. Find the largest number c such that c = a+b, where a, b, c are distinct
numbers of the set. If no c such exists, you should print “No Output”.
Sample Input:
2
7
1 6 10 3 14 18 51
6
7 3 1 9 4 5
Sample Output:
No Output
9 4 5.
Order the set in ascending order and start at the largest number c. Search downwards
and try to find a and b such that a+b == c, if the largest possible a and b are < c
you can skipt that loop. It doesn't bring down the big-Oh value but it cant cut off
quite a bit.

kind regards,

Jos
Aug 5 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.