Write a function named mySplit that accepts an array of int, and calls a recursive reference function. Function MySplit should check whether the numbers in the array can be divided into 2 groups,
The sum of the numbers in each group will be the same.
Do not ignore or add numbers in the first array
All numbers that are a multiple of 5 must be in the same group.
All numbers that are duplicates of 3 (and not multiples of 5) must be in the second group.
I started writing the code, but I'm looking for some different ideas. Everything should be written in the recursive function and the boolean function should just return true or false
Examples:
mySplit ([1, 1]) → true
mySplit ([1, 1, 1]) → false
mySplit ([2, 4, 2]) → true
mySplit ([5, 21, 8, 15, 7]) → true
mySplit ([15, 10, 5]) → false
mySplit ([15, 8, 7]) → true
My code:
public static boolean mySplit(int[] nums)
{
int []arr1=null;
int []arr2 = null;
int index_1=0;int index_2=0;
for (int i = 0; i < nums.length; i++)
{
if(nums[i]%5==0)
{
arr1[index_1]+=nums[i];
index_1++;
}
if(nums[i]%3==0 && (!(nums[i]%5==0)))
{
arr2[index_2]=nums[i];
index_2++;
}
}
}
public static int myRecur(int[] nums,int[] nums1,int quelbdika)
{
if(quelbdika>4)
return 0;
boolean flag=true;
if(quelbdika==1)
{
int somm1=0,somm2=0;
for (int i = 0; i < nums1.length; i++)
{
somm2+=nums1[i];
}
for (int i = 0; i < nums.length; i++)
{
somm1+=nums[i];
}
if(somm1!=somm2)
flag=false;
}
if(flag)
return 1+myRecur(nums,nums1,quelbdika+1);
else {
return 0+myRecur(nums,nums1,quelbdika+1);
}
}
}