*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
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
+ 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🍀
+ 2
I'll fix it with that
23rd Aug 2017, 3:14 PM
ysraelcon
+ 2
@VcC impressive. But there's a syntax error, please correct it.
23rd Aug 2017, 7:20 PM
Sivan Tal
+ 1
.... and collect your Nobel prize (or Turing award). https://en.m.wikipedia.org/wiki/Partition_problem
23rd Aug 2017, 12:42 PM
VcC
+ 1
@VcC That's the reason why they should tell ME. I want that turing award!!!
23rd Aug 2017, 1:15 PM
Julian Fechner
+ 1
ready @Timon working for that example 👌
23rd Aug 2017, 4:11 PM
ysraelcon
+ 1
mine have also been debugged with @VcC's examples :)
24th Aug 2017, 3:38 PM
ysraelcon
23rd Aug 2017, 10:34 AM
Julian Fechner
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
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
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
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
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
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
26th Aug 2017, 1:52 PM
Julian Fechner
0
vote for your favorite coding language: https://code.sololearn.com/WJqfkcTEguBe/?ref=app
4th Oct 2017, 7:04 PM
Julian Fechner
7th Oct 2017, 12:12 PM
Julian Fechner
Актуальное сегодня
HELP ME