I’ve been couple days now trying to figure it out how to return the longest sequence values from an array.

Ex: given –> int[] myArray = {1, 2, 3, 5, 7, 11, 12, 13, 14};

it should return back –> [11,12,13,14]

because the length of this sequence is 4 and the length of the other sequence (1,2,3) it just 3. My problem have been, I can’t stop the loop adding numbers to set1 once, no more sequence are found and then start adding again numbers to the other set2 if more sequence number are found in the list. Thanks in advance.

public static void sequenceValues(int[] value) {

```
Set<Integer> currentSecuence = new HashSet<>();
Set<Integer> longestSecuence = new HashSet<>();
int numbersLength = value.length;
for (int i = 0; i < numbersLength; i++) {
int current = value[i];
if (i < numbersLength - 1) {
if (current == value[i + 1] - 1) {
currentSecuence.add(current);
currentSecuence.add(value[i + 1]);
} else if (current != value[i + 1] - 1) {
}
if (currentSecuence.size() > longestSecuence.size()) {
longestSecuence.addAll(currentSecuence);
}
}
}
System.out.println(longestSecuence);
}
```