Longest sequence

  • 10
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 (36)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Maxim Raitin Level 8, Tomsk, Russian Federation
24 February, 14:45
Omg.. 17 attempts...
Alaskian7134 Level 10, Iasi, Romania
7 January, 21:27
tested the code 20 times with 20 different sequences, everytime i got the right result, everytime got the error to be carrefull what happens if the longest sequnce is at the end. and tested 20 more times, again everything looked right and still got the error. it seems to be that the part with "do it exactly as we did it" it happens more often and often. funny part is... i looked at the solution and it was a lot like mine, but... they wanted to be exactly the same i guess...
Roman Level 41
8 January, 06:40
Please post your question with the attached solution in the section Help. Or send me you solution in PM, I'll check it.
kar-fai chow Level 8, Hong Kong, Hong Kong
22 November 2020, 12:38
so why does integer >127 matters? what is going on?
kar-fai chow Level 8, Hong Kong, Hong Kong
22 November 2020, 12:52
never mind, found it: "The issue is that your two Integer objects are just that, objects. They do not match because you are comparing your two object references, not the values within. Obviously .equals is overridden to provide a value comparison as opposed to an object reference comparison." "The JVM is caching Integer values. Hence the comparison with == only works for numbers between -128 and 127." https://stackoverflow.com/questions/3637936/java-integer-equals-vs
Chandan Thapa Level 22, Dubai, United Arab Emirates
19 October 2020, 18:52
took me almost 2.3 hrs,, hardest so far for me on the course..
Roman Hryhorchuk Level 17, Cracow, Poland
24 September 2020, 10:25
I believe that my way how I did this is not very handy (two arrays, 10 for loops), but it works and passed in 7 attempts
George Level 15, United Kingdom
13 September 2020, 12:50
This one was a bit hard. Took me 45mins. I still don't like my method that much. I feel like there's a better way. My issue was that it wasn't working when the sequence was at the end of the list. So I'm adding to my counter list after the "for" loop as well, to make up for it. Any better ideas?
Karas Level 16, Tampa, United States
10 September 2020, 23:24
As an additional comment after 5 verifications... make sure you use .equals(); Also for me after 8 hours, 5 verifications, 3 capuccinos I am done for the day.
Cam Level 14, Bogota, Colombia
1 October 2020, 21:58
Thank you, if it weren't for these comment, I'd have spent a lot of time on this task (knowing myself probably a couple of days)
Andrei Level 20
2 November 2020, 17:03
why? for me it works with == also ? can you please explain?
Karas Level 16, Tampa, United States
3 November 2020, 00:57
It also works but there was a point or part where it was the same and it did not validate. With ints and integers works but with strings is better .equals(); There is an entire article about it. But if it works it works.
Andrei Level 20
3 November 2020, 07:27
Ah ok. I knew about equals with strings, did not know about equals with ints.
Petros Level 23, Columbia, United States
24 July 2020, 01:34
I need a break after this one. I did it with 3 if statements nested in a for loop. Took hours. I got a tip to use a couple integers for counting. Not easy but worth it.
frimpong kwame Level 8, Accra, Ghana
1 July 2020, 22:29
The longest sequence task was really hard for me.
Lucas Hoage Level 14, Savannah, United States
2 June 2020, 02:53
Very high difficulty.