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.

Sulagna | 117 |

RUTVIKHARIPARA | 116 |

janvidavda105190 | 93 |

harshsiddhapura105461 | 93 |

devsinghindra | 80 |

PiyushPandey4 | 614 |

ASWATHAMA | 561 |

akhyasharma01 | 547 |

john_wick | 521 |

jagrit_07 | 443 |

blackshadows | 5362 |

Ibrahim Nash | 5242 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4598 |

Login to report an issue on this page.