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.

bhatabhi554 | 317 |

hardikJain5 | 306 |

CodeBuddy | 293 |

Akkki111 | 233 |

clone | 230 |

KshatriyaYash | 1932 |

nikhil_sojan | 1374 |

lonecoder | 1236 |

mazumderrohit8 | 1176 |

RemoveTLE | 1144 |

blackshadows | 5327 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4605 |

Quandray | 4444 |

Login to report an issue on this page.