+ 16
The collection of number is given in 2d array is [4,5,3,2] and how can we set algorithm to get sum = 10 ?
From using array such as [4,5,3,2] => sum = 10 ... Take one another collection also let it be [9,7,2,3] => sum =10
8 ответов
+ 14
If I understand your question then this is the code which gives you the sum of the 2D table
https://code.sololearn.com/Wlhxs4y3Lddp/?ref=app
+ 12
No that algorithm wouldn't valid here that was sum of total collection of number in array but here i want sum = 10 exactly using no. of array which i provide if you applied that algorithm here the answer you will get 14 but i want sum = 10 exactly
+ 12
In next example we will have to address only 7 & 3 with their index no. to get sum =10 😄 on the methodology of choose the best fu*k the rest😂 Denise Roßberg
+ 10
Can be called Choe i think
+ 5
With a pair it is easy:
Inside a loop you take the first value --> if list contains 10 - first value --> pair found
else: try next value in your list
More than two nums:
I think to calc the full sum is not a bad idea.
If full sum < 10 --> no sum can be found
else:
e.g. 4 + 5 + 3 + 2 = 14
14 - 10 = 4 --> inside a loop you can search: if(list contains full sum - 10) --> remove this element
In your next example full sum is 21. You don't have an 11 in your array. So you need to search if you have 2 or more nums in your list which sum is 11 (here: 9 + 2)
+ 2
In python:
L=[4,5,3,2]
Sum=0
for i in L:
Sum=Sum+(i-1)
print(sum)
+ 1
hm, this question seems oddly familiar to something ive seen before.. what was it again?
https://www.sololearn.com/learn/4755/
+ 1
you can use the knapsack algorithm .. Google it ..for the given sack of 10 you can use either the greedy method or the dynamic method to add the weights into the sack weights here are your array elements to the sack until its full