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.

**OUTPUT :** Print the required sub-array.

**CONSTRAINTS :**

1<=T<=100

1<=n,a[i]<=10^{4}

**EXAMPLES :
INPUT :**

2

5

1 2 1 1 2

6

3 2 5 2 3 3

**OUTPUT :**

1 2 1 1

3 2 5 2 3 3

Author: saksham0751

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

vamsikrishna55 | 162 |

Vagesh Verma | 158 |

UrGuru | 133 |

abducodes | 127 |

Akhil varma | 114 |

abducodes | 683 |

harshtyagi36 | 322 |

Akhil varma | 267 |

arpit_anshuman | 258 |

highway_to_hell | 252 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4567 |

Login to report an issue on this page.