Smallest sub-array with all occurences of most frequent element

Easy Accuracy: 15.88% Submissions: 912 Points: 2

Given an array, A.Let x be an element in the array which has the maximum frequency in the array.Find the smallest subsegment of the array which also has x as the maximum frequency element. NOTE : If there are two or more such sub-arrays then print the sub-array that is ending first(last index is least).
Examples:

Input : arr[] = {4, 1, 1, 2, 2, 1, 3, 3}
Output : 1, 1, 2, 2, 1
The most frequent element is 1. The smallest
subarray that has all occurrences of it is
1 1 2 2 1
Input : A[] = {1, 2, 2, 3, 1}
Output : 2, 2
Note that there are two elements that appear
two times, 1 and 2. The smallest window for
1 is whole array and smallest window for 2 is
{2, 2}. Since window for 2 is smaller, this is
our output.

INPUT : The first line consists of an integer T i.e. the number of test cases. First line of each test case consists of a integer n. Second and last line of each test case consists of n spaced integers.