+ 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

1st Aug 2017, 11:47 AM
aziz
aziz - avatar
23 Antworten
1st Aug 2017, 6:52 PM
Said BAHAOUARY
Said BAHAOUARY - avatar
1st Aug 2017, 2:58 PM
Krishna Teja Yeluripati
Krishna Teja Yeluripati - avatar
+ 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
1st Aug 2017, 2:59 PM
Apoorva Shenoy Nayak
Apoorva Shenoy Nayak - avatar
+ 10
thank you @Aziz ☺
2nd Aug 2017, 11:30 AM
Said BAHAOUARY
Said BAHAOUARY - avatar
+ 9
Leave an answer and you'll be able to find it whenever you want
1st Aug 2017, 2:39 PM
The Coding Sloth
The Coding Sloth - avatar
+ 7
don't send wrong challenge @aziz
2nd Aug 2017, 9:05 AM
Said BAHAOUARY
Said BAHAOUARY - avatar
+ 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 ^^) >>
1st Aug 2017, 9:04 PM
visph
visph - avatar
+ 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
2nd Aug 2017, 6:53 AM
aziz
aziz - avatar
+ 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 ^^
2nd Aug 2017, 8:53 AM
visph
visph - avatar
+ 4
@krishna & @apoorva Great i test your codes when i come back to home
1st Aug 2017, 3:03 PM
aziz
aziz - avatar
+ 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
1st Aug 2017, 8:05 PM
aziz
aziz - avatar
+ 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?
1st Aug 2017, 2:37 PM
lion
lion - avatar
+ 2
@lion yes this is the solution but i think there are another way better than this for solving this problem
2nd Aug 2017, 6:59 AM
aziz
aziz - avatar
+ 2
@Garikai your attempt is not correct
2nd Aug 2017, 7:05 AM
aziz
aziz - avatar
+ 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
2nd Aug 2017, 8:37 AM
aziz
aziz - avatar
+ 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
2nd Aug 2017, 11:29 AM
aziz
aziz - avatar
+ 2
Thanks Aziz for the challenge! 😊
2nd Aug 2017, 5:19 PM
Apoorva Shenoy Nayak
Apoorva Shenoy Nayak - avatar
1st Aug 2017, 6:36 PM
Garikai
Garikai - avatar
+ 1
Krishna Teja Yeluripati i can't challenged you how i can send you a 100 xps??
2nd Aug 2017, 6:54 AM
aziz
aziz - avatar