#K35377. Largest Mirror Section
Largest Mirror Section
Largest Mirror Section
You are given an array of integers. A mirror section in an array is a group of contiguous elements such that somewhere in the array, the same group appears in reverse order. Your task is to find the size of the largest mirror section in the array.
For example, if the array is:
1 2 3 8 9 3 2 1
Then one of its mirror sections is 1 2 3 at the beginning and 3 2 1 at the end. Thus, the largest mirror section has a size of 3.
Mathematically, if S is a contiguous subsequence of the array and T is another contiguous subsequence such that
S = \(a_i, a_{i+1}, \dots, a_{i+k-1}\)
and
T = \(a_j, a_{j-1}, \dots, a_{j-k+1}\),
then the mirror length is \(k\). Find the maximum \(k\) for which such subsequences exist.
inputFormat
The first line contains a single integer \(n\) (\(0 \leq n \leq 10^5\)) representing the number of elements in the array.
The second line contains \(n\) space-separated integers representing the array elements.
Note: When \(n = 0\), the array is empty.
outputFormat
Output a single integer denoting the size of the largest mirror section found in the given array.
## sample8
1 2 3 8 9 3 2 1
3
</p>