Arrays Exercises: Max Sequence of Equal elements
Здравейте, опитвам се да реша това упражнение със subsequence , но ми дава 90/100 и не мога да разбера къде е проблемът.
https://pastebin.com/9swf8mAt
Ето условието :
8.Max Sequence of Equal Elements
Write a program that finds the longest sequence of equal elements in an array of integers. If several longest sequences exist, print the leftmost one.
Examples
Input |
Output |
2 1 1 2 3 3 2 2 2 1 |
2 2 2 |
1 1 1 2 3 1 3 3 |
1 1 1 |
4 4 4 4 |
4 4 4 4 |
0 1 1 5 2 2 6 3 3 |
1 1 |
Hints
-
Start with the sequence that consists of the first element: start=0, len=1.
-
Scan the elements from left to right, starting at the second element: pos=1…n-1.
-
At each step compare the current element with the element o8he left.
-
Same value you have found a sequence longer by one len++.
-
Different value start a new sequence from the current element: start=pos, len=1.
-
-
After each step remember the sequence it is found to be longest at the moment: bestStart=start, bestLen=len.
-
-
Finally, print the longest sequence by using bestStart and bestLen
Много благодаря