+ 12
Who can resolve this problem he will win 100 Xps
i have a challenge little difficult for you: make a boolean function , that's take a integer list as parameter and return true if we can seperate this list into two , the sum of their elements is identic exemple : isSeparatedList([ 2 ,10 ,7 ,1,5,9] ) = true bcz : sum of [10,7] = sum of [2,1,5,9] isSeparatedList( [ 5 , 4 , 3, 1] ) = false good luck
23 Antworten
+ 7
try this one
https://code.sololearn.com/wycVEA4tdm4E/?ref=app
+ 17
+ 10
The logic/concept applied:
1) Calculate sum of the array. If sum is odd, there can not be two subsets with equal sum, so return false.
2) If sum of array elements is even, calculate sum/2 and find a subset of array with sum equal to sum/2.
Recursive Solution:
Let isSubsetSum(arr, n, sum/2) be the function that returns true if there is a subset of arr[0..n-1] with sum equal to sum/2 The isSubsetSum problem can be divided into two subproblems a) isSubsetSum() without considering last element (reducing n to n-1) b) isSubsetSum considering the last element (reducing sum/2 by arr[n-1] and n to n-1) If any of the above the above subproblems return true, then return true. isSubsetSum (arr, n, sum/2) = isSubsetSum (arr, n-1, sum/2) || isSubsetSum (arr, n-1, sum/2 - arr[n-1])
Here's the code: https://code.sololearn.com/caUbtqi63I4w/?ref=app
+ 10
thank you @Aziz ☺
+ 9
Leave an answer and you'll be able to find it whenever you want
+ 7
don't send wrong challenge @aziz
+ 5
Don't multi post your question:
https://www.sololearn.com/Discuss/515417/?ref=app
https://www.sololearn.com/Discuss/583612/?ref=app
And at least answer in the other threads ^^
<< My JS attempt:
https://code.sololearn.com/Wc322WRTyTfj/#js
(I'm not sure of the logic implemented: feel free to test it with various arrays ^^) >>
+ 5
@pikatchu i test your code with this list : [12 20 5 7 6] and it print false but it's true because [12 20 5 7 6] = ([20 5 ] , [12 6 7]) true
i test all your attempts and the winners is :
Krishna Teja Yeluripati , visph , Said bahaouari , Apoorva Shenoy Nayak
+ 5
@aziz wrote:
<< i test all your attempts and the winners is :
Krishna Teja Yeluripati , visph , Said bahaouari , Apoorva Shenoy Nayak >>
<<Krishna Teja Yeluripati
i can't challenged you how i can send you a 100 xps?? >>
You cannot also challenge me... this seems to not disrupt you ^^
+ 4
@krishna & @apoorva Great
i test your codes when i come back to home
+ 4
Garikai thank you thank you for traying if you test your function with [6 , 5, 9] it will output true but the right input is false
+ 3
after determining that the total sum is even, try to find the half sum with a combinations-like algorithm ..I think. How do I bookmark this question to come back to it with the code?
+ 2
@lion yes this is the solution but i think there are another way better than this for solving this problem
+ 2
@Garikai
your attempt is not correct
+ 2
@pikatshu i send to them a challenges which i put wrong answers to all of questions of those challenges
if you have another idea tell us
+ 2
@pikatchu you are right it's not a good way to losing my xp
for you the person who read this comment, don't forget after you finish, to up vote the codes of those heros, who arrive to resolve the problem .
Krishna Teja Yeluripati , visph , Said bahaouari , Apoorva Shenoy Nayak
+ 2
Thanks Aziz for the challenge! 😊
+ 1
Did I get it right?
https://code.sololearn.com/cDszwHX4J4Zj/?ref=app
+ 1
Krishna Teja Yeluripati
i can't challenged you how i can send you a 100 xps??