I was trying to increment count as when a potential sequence was beginning. Save it to a different variable and as soon as the sequence was broken reset count but have the longest sequence still saved.
package com.codegym.task.task08.task0812;
import java.io.*;
import java.util.ArrayList;
/*
Longest sequence
Set<String> store = new HashSet<>();
// for (String name : names) { if (store.add(name) == false)
// { System.out.println("found a duplicate element in array : " + name); } }
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
ArrayList<Integer> nbrs = new ArrayList<Integer>();
for(int i = 0; i < 10; i++)
{
int n = Integer.parseInt(reader.readLine());
nbrs.add(n);
}
int result = 0;
int count = 0;
for (int i = 1; i < nbrs.size(); i++)
{
if(nbrs.get(i - 1) == nbrs.get(i))
{
count++;
if(count > result)
{
result = count;
}
} else
{
count = 0;
}
}
System.out.println(result);
}
}