I have had this problem for an interview and can't seem to wrap my mind around how to solve it. I have not found any tutorials that explains the logic behind it as well.
Have the function ArrayChallenge(arr), take the array of integers stored in arr which will always contain an even amount of integers, and determine how they can be split into two even sets, then return a string representation of the first set followed by the second set with each integer separated by a comma and both sets sorted in ascending order. The set that goes first is the set with smallest first integer.
For example if arr is [16,22,35,8,20,1,21,11], then your program should output 1,11,20,35,8,16,21,22
[16,22,35,8,20,1,21,11] sum = 134
the sum of 1,11,20,35 is = 67 the sum of 8,16,21,22 is = 67
Also the size of the two arrays are equal to arr.length /2
you would use an iteration and traverse the array first. then you make 2 integers. In each iteration cycle, you first check if integer1 is bigger than integer2. then put one number in array1 and add its value to integer1. repeat. if int1 is bigger than int2, you put it in array2 and add the value to int2. in the end, sort the array and you are done. that is how I would solve it. Does this work? I am genuinely interested.