+ 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
30 Respostas
+ 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
+ 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
+ 2
I'll fix it with that
+ 2
@VcC impressive. But there's a syntax error, please correct it.
+ 1
.... and collect your Nobel prize (or Turing award). https://en.m.wikipedia.org/wiki/Partition_problem
+ 1
@VcC
That's the reason why they should tell ME.
I want that turing award!!!
+ 1
ready @Timon working for that example 👌
+ 1
mine have also been debugged with @VcC's examples :)
0
ANOTHER MINI-CHALLENGE HERE:
https://www.sololearn.com/discuss/650079/?ref=app
0
Here's my Python solution.
The solution uses the Python itertools library - part of the builtin library.
https://code.sololearn.com/c7CCEij0j58D
0
AS FAR AS I KNOW, BEST RUNTIME STILL IS EXPONENTIAL... IF YOU FIND A BETTER SOLUTION LET ME KNOW!!!
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
0
this works for question's examples, @Timon's example and @VcC's examples
https://code.sololearn.com/WFmlWqvA4Jpq/?ref=app
0
1, 1, 2, 3, 5, 4
doesn't work, ysraelcon.
Is nothing, should be
1 + 1 + 2 + 4 = 8
3 + 5 = 8
0
A debug version of my code so that you can see what it does:
https://code.sololearn.com/c7nKhvn9zuon/?ref=app
0
NEW *DAILY CHALLENGE* HERE:
https://www.sololearn.com/discuss/659673/?ref=app
0
NEW *DAILY CHALLENGE* HERE:
https://www.sololearn.com/discuss/659673/?ref=app
0
vote for your favorite coding language:
https://code.sololearn.com/WJqfkcTEguBe/?ref=app
0
my mew challenge:
https://www.sololearn.com/discuss/770421/?ref=app