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 {
BufferedReader kb = new BufferedReader(new InputStreamReader(System.in));
ArrayList<Integer> lst = new ArrayList<Integer>();
for (int i = 0; i < 10; i++)
{
lst.add(Integer.parseInt(kb.readLine()));
}
int longest = 0, current = 0;
for (int i = 0; i < 10; i++)
{
try
{
if (lst.get(i).equals(lst.get(i + 1)))
{
current++;
}
}
catch (Exception e)
{
if (longest < current)
{
longest = current;
}
}
}
if (longest == 0)
System.out.println(1);
else
System.out.println(longest);
}
}
Code fails "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. " even though output succeeds.
Under discussion
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Show How
6 May 2020, 18:23
after the condition where you check if longest is less than current and assigning current to longest, you need to reset the current so the new sequence can be captured. Hope it helps.
0
Nouser
30 April 2020, 07:47
you save current into longest only once, when the loop is at its end
If you have two sequences 11112222 current gets increased to 3 for all the ones. Then it's getting increased for additional 3 cause of the twos. So current is 6 and it's getting saved now into longest
0