Recommendation : Be sure that the length of the longest sequence is calculated correctly when it is located at the end of the list of entered numbers.
It returns 2 when tried with
2
4
14
4
8
8
4
12
12
12
please how do I fix this ?
package com.codegym.task.task08.task0812;
import java.io.*;
import java.util.ArrayList;
/*
Longest sequence
*/
public class Solution {
public static void main(String[] args) throws IOException {
//write your code here
int maxCount = 0;
int count = 0;
ArrayList<Integer> list = new ArrayList<Integer>();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
for(int i = 0; i < 10; i++){
int n = Integer.parseInt(br.readLine());
list.add(n);
}
for(int i = 0; i < list.size()-1; i++){
if(list.get(i) == list.get(i + 1)){
count++;
}else{
if( count > maxCount){
maxCount = count;
}
count = 1;
}
}
System.out.println(maxCount);
}
}