public static int[] interleave(int[] a, int[] b) {
int resultLength = a.length + b.length;
int[] c = new int[resultLength];
c[0] = a[0];
c[1] = b[0];
for(int i = 1; i < resultLength - 1; i++) {
if(c[i-1] == a[i-1]) {
c[i] = b[i];
}
else if(c[i-1] == b[i-1]) {
c[i] = a[i];
}
else if(a[i-1] == b[i-1]) {
c[i] = a[i];
}
}
return c;
}
public static void main(String args[]) {
int[] a = {1,1,1,1,1};
int[] b = {2,2,2,2,2};
System.out.println(Arrays.toString(S2020Mini2.interleave(a, b)));
I am getting an ArrayIndexOutOfBoundsException error and I would appreciate some help in solving this issue. Thank you for your help.