#C14823. Longest Palindromic Subarray

    ID: 44515 Type: Default 1000ms 256MiB

Longest Palindromic Subarray

Longest Palindromic Subarray

Given an array of integers, your task is to find the longest contiguous subarray that forms a palindrome. A palindrome is a sequence that reads the same forwards as it does backwards. In case there are several subarrays with the maximum length, return the one that appears first in the array.

Note: The subarray must consist of consecutive elements from the original array.

For example, if the input array is [1, 2, 3, 2, 1, 4, 5, 4, 6], the longest palindromic subarray is [1, 2, 3, 2, 1].

inputFormat

The first line contains an integer n, the number of elements in the array. The second line contains n space-separated integers denoting the array elements.

outputFormat

Output the longest contiguous subarray that is a palindrome. The elements should be printed in order, separated by a single space on one line.## sample

5
1 2 3 2 1
1 2 3 2 1