+ 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
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
+ 3
wow
+ 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
0
And here is the one liner version !
https://code.sololearn.com/crBZYq2Ck2d1/?ref=app