# Longest sequence

• 5
• Locked
• Exercise
If numbers repeat themselves, does that mean that somebody wants it that way? At present, we need repeated numbers to practice completing tasks with lists. Let's create a list of numbers and add 10 numbers from the keyboard. Our task is to display the length of the longest sequence of repeating numbers in a list.
You can't complete this task, because you're not signed in.
PritinaikLevel 8 , Mumbai
30 August, 17:30
Whats wrong with my code? the last requirement is not met whereas i am getting the correct answer.
VrhLevel 9 , Zagreb
13 July, 16:59
Loved this assignment. It was cool to get an error message about numbers bigger than 128 and than figuring it out.
13 July, 14:51
It is strange that if(127==127) evaluates to true but (128==128) evaluates to false. Maybe it has to do something with the reference type. Hint 1: Use 2 counters, first counter will be assigned the longest occurrence and the second counter will be used to get the occurrences for each set. Hint 2: Use equals method of the Integer class do not use the comparing operator since the Reference objects are dealt(so it will produce weird result in case of numbers greater than 127).
28 September, 23:02
6 June, 19:48
I have tried all possible testcases and it is giving right answer but after submission its not passing.
RomanLevel 41
7 June, 07:22
If you need help, something isn't right in your code, the server won't accept your solution (even if you are 100% sure that it is correct). Describe your question/issue in the HELP section at codegym.cc/help.
RyanLevel 14 , Ashburn
18 February, 21:05
My favorite one so far, made me realize how much I've learned.
Grigore TurcanLevel 9 , Chisinau
11 January, 12:47
arvindsidLevel 10 , Chennai
26 December 2018, 18:02
i have verified the following code with all possible scenarios and my results are correct but still it fails verification
``````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 {

ArrayList<Integer> listNum =  new ArrayList<Integer>();
int[] seqArray = new int[10];
int matchNum = 0;
int matchCount = 0;

for (int i=0;i<10;i++)
{
}

for(int i=0;i<10;i++)
{

matchNum = listNum.get(i);
//    System.out.println("matchNum:"+ matchNum);
matchCount =1;
for(int j=i+1;j<10;j++)
{
if (matchNum == listNum.get(j))
{
matchCount++;
}
}
//  System.out.println("matchCount:"+ matchCount);

seqArray[i] = matchCount;
}
// find the longest sequence in the sequence array

int s = seqArray[0];
int l = seqArray[0];

for(int i = 1; i < seqArray.length; i++) {
if(seqArray[i] > l)l = seqArray[i];
else if (seqArray[i] < s)s = seqArray[i];
}

System.out.println(l);

}
}``````
RomanLevel 41
27 December 2018, 06:48
If you need help, something isn't right in your code, the server won't accept your solution (even if you are 100% sure that it is correct). Describe your question/issue in the HELP section at codegym.cc/help.