×

Loading...

Java Implementation is here:

public static int getMaxSeqSize(int... input) {
Arrays.sort(input);
int maxLen = 1;
int end = input.length - maxLen;
for (int first = 0; first < end; first++) {
for (int second = first + 1; second <= end; second++) {
int leap = input[second] - input[first];
int next = input[second] + leap;
int len = 2;
for (int i = second +1; i < input.length; i++) {
if (input[i] == next) {
len++;
next += leap;
} else if (input[i] > next) {
break;
}
}
if (len > maxLen) {
maxLen = len;
end = input.length - maxLen;
}
}
}
return maxLen;
}
Report