*DAILY CHALLENGE* : Write a function that splits a given integer array into 2 arrays so that the sums of them are equal! | Sololearn: Learn to code for FREE!
+ 7

*DAILY CHALLENGE* : Write a function that splits a given integer array into 2 arrays so that the sums of them are equal!

EXAMPLE 1: array = [1,3,2] arr1 = [1,2] = 3 arr2 = [3] = 3 ---> return [[1,2,],[3]] EXAMPLE 2: array = [2,7,3,1,2,1] arr1 = [1,7] = 8 arr2 = [3,2,1,2] = 8 ---> return [[1,7],[3,2,1,2]] EXAMPLE 3: array = [1,2,4] --> NOT POSSIBLE --> return empty array

23rd Aug 2017, 9:39 AM
Julian Fechner
Julian Fechner - avatar
30 ответов
+ 2
Here is the pseudo polynomial time one using dynamic programming. Note that it looks polynomial but uses LOTS of memory so that the other versions will often be faster https://code.sololearn.com/c48gJx2v07hc/?ref=app
23rd Aug 2017, 7:14 PM
VcC
VcC - avatar
+ 2
Wow I have a code that do exactly the same thing! The description is a little bit different, though. https://code.sololearn.com/chOGvMxzz5UY/?ref=app And this is the edited one: https://code.sololearn.com/ceaePxuN0MUZ/?ref=app
23rd Aug 2017, 9:59 AM
hmysjiang🍀
hmysjiang🍀 - avatar
+ 2
I'll fix it with that
23rd Aug 2017, 3:14 PM
ysraelcon
ysraelcon - avatar
+ 2
@VcC impressive. But there's a syntax error, please correct it.
23rd Aug 2017, 7:20 PM
Sivan Tal
Sivan Tal - avatar
+ 1
.... and collect your Nobel prize (or Turing award). https://en.m.wikipedia.org/wiki/Partition_problem
23rd Aug 2017, 12:42 PM
VcC
VcC - avatar
+ 1
@VcC That's the reason why they should tell ME. I want that turing award!!!
23rd Aug 2017, 1:15 PM
Julian Fechner
Julian Fechner - avatar
+ 1
ready @Timon working for that example 👌
23rd Aug 2017, 4:11 PM
ysraelcon
ysraelcon - avatar
+ 1
mine have also been debugged with @VcC's examples :)
24th Aug 2017, 3:38 PM
ysraelcon
ysraelcon - avatar
23rd Aug 2017, 10:34 AM
Julian Fechner
Julian Fechner - avatar
0
Here's my Python solution. The solution uses the Python itertools library - part of the builtin library. https://code.sololearn.com/c7CCEij0j58D
23rd Aug 2017, 12:26 PM
Sivan Tal
Sivan Tal - avatar
0
AS FAR AS I KNOW, BEST RUNTIME STILL IS EXPONENTIAL... IF YOU FIND A BETTER SOLUTION LET ME KNOW!!!
23rd Aug 2017, 12:37 PM
Julian Fechner
Julian Fechner - avatar
0
Here you go. Original array is randomly filled, so you're going to get a lot of Not possible output, but when the sum is equal, output is correct. https://code.sololearn.com/c7TC16350rAy/?ref=app
23rd Aug 2017, 12:43 PM
Vari93
Vari93 - avatar
0
this works for question's examples, @Timon's example and @VcC's examples https://code.sololearn.com/WFmlWqvA4Jpq/?ref=app
23rd Aug 2017, 2:31 PM
ysraelcon
ysraelcon - avatar
0
1, 1, 2, 3, 5, 4 doesn't work, ysraelcon. Is nothing, should be 1 + 1 + 2 + 4 = 8 3 + 5 = 8
23rd Aug 2017, 3:04 PM
Timon Paßlick
23rd Aug 2017, 4:28 PM
Izi Lior Katie
Izi Lior Katie - avatar
0
A debug version of my code so that you can see what it does: https://code.sololearn.com/c7nKhvn9zuon/?ref=app
23rd Aug 2017, 9:34 PM
Timon Paßlick
26th Aug 2017, 1:51 PM
Julian Fechner
Julian Fechner - avatar
26th Aug 2017, 1:52 PM
Julian Fechner
Julian Fechner - avatar
0
vote for your favorite coding language: https://code.sololearn.com/WJqfkcTEguBe/?ref=app
4th Oct 2017, 7:04 PM
Julian Fechner
Julian Fechner - avatar
7th Oct 2017, 12:12 PM
Julian Fechner
Julian Fechner - avatar