#105. 数组最大跨度
数组最大跨度
Maximum Span in Array
Background
Congcong is currently studying the properties of arrays. He found that the occurrences of identical elements in an array can sometimes be interesting, so he defined a new concept: "span".
Problem Description
Consider the leftmost and rightmost appearances of some value in an array. We'll say that the "span" is the number of elements between the two inclusive. A single value has a span of . Returns the largest span found in the given array. (Efficiency is not a priority.)
Input Format
Input is given from standard input in the following format.
A single line containing several space-separated integers, representing the elements of the array.
Output Format
Output to standard output in the following format.
A single integer, representing the largest span found in the array.
Sample
1 2 1 1 3
4
1 4 2 1 4 1 4
6
1 4 2 1 4 4 4
6
Sample Explanation
Sample 1: For the array [1, 2, 1, 1, 3]:
- Value appears leftmost at index and rightmost at index . The span is .
- Value appears leftmost at index and rightmost at index . The span is .
- Value appears leftmost at index and rightmost at index . The span is . The maximum span is .
Sample 2: For the array [1, 4, 2, 1, 4, 1, 4]:
- Value appears leftmost at index and rightmost at index . The span is .
- Value appears leftmost at index and rightmost at index . The span is .
- Value appears leftmost at index and rightmost at index . The span is . The maximum span is .
Sample 3: For the array [1, 4, 2, 1, 4, 4, 4]:
- Value appears leftmost at index and rightmost at index . The span is .
- Value appears leftmost at index and rightmost at index . The span is .
- Value appears leftmost at index and rightmost at index . The span is . The maximum span is .
Constraints
Time limit: second, Memory limit: KiB for each test case.