public static int[] longestSeq(int[] a) {
int longestSeq = 1;
int longestInd = 0;
for (int i = 0; i < a.length-1; i++) {
int counter = 1;
while (a[i] == a[i + 1]){
counter++;
i++;
}
if (counter > longestSeq){
longestSeq = counter;
longestInd = i;
}
}
return new int[] {longestSeq, longestInd};
}
What is the error? The code is trying to find out the longest contiguous sequence in an array of integers. What could be a way to do that?