+ 3

[CHALLENGE]

Write a program to accept an array of doubles (floating values) from the user, and get a target value. Program should return the minimum number of elements that sum up to the target value. Input Format :- First line contains the number of elements in the array(n). Next line has n elements of the array. 3rd line accepts the target. Output format :- First line outputs the minimum number of elements. SAMPLE Input :- 6 1,2,3,4,-6,8 Target :- 8 Output :- 8 Target :- -5 Output :- -6,1

16th Nov 2017, 7:26 AM
Meharban Singh
Meharban Singh - avatar
4 Answers
+ 3
optimized exponential code. Simpler and returns the solution you expect but unable to deal with very large cases https://code.sololearn.com/cXY0TpedHsBP/?ref=app
16th Nov 2017, 1:04 PM
VcC
VcC - avatar
+ 3
wow
27th Nov 2017, 8:30 PM
Meharban Singh
Meharban Singh - avatar
+ 2
polynomial time solution. Needs mods to return the smallest nr of items and algo limited to non negative numbers, but it is as fast as you can be https://code.sololearn.com/ce66BP2wZ4hl/?ref=app
16th Nov 2017, 9:09 AM
VcC
VcC - avatar
0
And here is the one liner version ! https://code.sololearn.com/crBZYq2Ck2d1/?ref=app
27th Nov 2017, 7:41 PM
VcC
VcC - avatar