Function Loop Detection
InterviewTime limit1sMemory limit1024 MB
Find the segment of distinct function names that repeats consecutively the most times in a call list, then print its length, repeat count, and contents.
- Level
Medium6 of 10
- Topics
- Array, Hash map, Sliding window
- Solved
- No attempts yet
Problem
Ikjun has a function call list that records the names of the functions called during a program run. He wants to find the segment of consecutive calls that repeats the most times in a row, where every element in the segment is distinct.
For example, contains the segment twice.
In , the segment repeats consecutively, but the name appears twice in it, so it does not satisfy the condition.
Input
The first line contains an integer . ()
The second line contains strings separated by spaces. Each string consists of uppercase English letters only. ()
Output
The first line prints the length and the number of repetitions of the segment that appears first among the segments repeated the most times.
The second line prints that function call segment, with its elements separated by spaces.
If no segment repeats more than once, print only -1.
Hint
is the length of the string .