Longest sequence

  • 5
  • Locked
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.
Comments (6)
  • Popular
  • New
  • Old
You must be signed in
Jatin MadaanLevel 14 , Mumbai
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
Please help, what is wrong in my code ?
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];
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int matchNum = 0;
        int matchCount = 0;

        for (int i=0;i<10;i++)
        {
            listNum.add(Integer.parseInt(reader.readLine()));
        }

        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.