Number Sequence
Time limit1sMemory limit1024 MB
Given a sequence of 1, 2, 4, and 8, find the longest run of equal adjacent values and count the windows of four consecutive elements that contain all four values.
- Level
Easy2 of 10
- Topics
- Array, Implementation
- Solved
- No attempts yet
Statement
The number sequence consists only of the numbers 1, 2, 4, and 8. Some of these numbers may not appear in the sequence. Write a program seq that answers two questions:
- What is the length of the longest contiguous subsequence whose elements all have the same value?
- How many groups of four consecutive elements contain all four numbers 1, 2, 4, and 8 in some order?
Input
The first line of standard input contains a positive integer , the number of elements in the sequence. The second line contains the values of the sequence, separated by single spaces. Each value is 1, 2, 4, or 8.
Output
Print one line to standard output with two integers separated by a single space. The first is the length of the longest run of equal consecutive elements. The second is the number of groups of four consecutive elements that contain all of 1, 2, 4, and 8.
Constraints
Hint
In the example, the longest run of equal adjacent elements is 8, 8, 8, so the first answer is 3. The four groups of consecutive elements that contain all of 1, 2, 4, and 8 are 8, 1, 2, 4; 1, 2, 4, 8; 2, 4, 8, 1; and 4, 8, 1, 2.