package com.codegym.task.task08.task0812;
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
/*
Longest sequence
*/
public class Solution {
public static void main(String[] args) throws IOException {
InputStreamReader r = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(r);
ArrayList<Integer> list = new ArrayList();
for(int i = 0; i < 10; i++){
list.add(Integer.parseInt(br.readLine()));
}
int counter = 1;
ArrayList<Integer> maxes = new ArrayList();
for(int i = 0; i < 9; i++){
if(list.get(i).equals(list.get(i + 1))){
counter++;
maxes.add(counter);
} else{
counter = 1;
}
}
Collections.sort(maxes);
int max = maxes.get(maxes.size() -1);
System.out.println(max);
}
}
Can't see why this won't pass??
Under discussion
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Guadalupe Gagnon
15 February 2020, 06:26
If all the numbers are different no value will be added to "maxes" because adding values is behind the if statement when 2 consecutive numbers are equal. Line 35 will throw an exception in this scenario when it tries to access index -1.
0
Hankster
15 February 2020, 17:31
Thanks! I took out that part and put this above the for loop: maxes.add(1); Now it works!
+1