Timer is Running

Given an array A. Let X be an element in the array which has the maximum frequency. The task is to find the smallest sub segment of the array which also has X as the maximum frequency element.

**Note:** if two or more elements have the same frequency (i.e., maximum frequency) and the same sub segment size then print the sub segment** **which occurs first in the array.

**Input:**

The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of two lines. First line of each test case contains an Integer N denoting size of array and the second line contains N space separated elements.

**Output:**

For each test case, print the required sub segment of array in new line.

**Constraints:**

1<=T<=100

1<=N<=10^{5}

1<=A[i]<=10^{5}

**Example:
Input:**

3

8

4 1 1 2 2 1 3 3

5

1 2 2 3 1

6

1 4 3 3 5 5

1 1 2 2 1

2 2

3 3

**Explanation:**

```
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.
```

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.

visutkarsh2000 | 251 |

ayushaggarwal821 | 248 |

ashishboss9977 | 236 |

tekuripurushotham | 178 |

ramharshrai1999 | 151 |

abnandi04 | 776 |

KshamaGupta | 499 |

ponnadasaikesav | 450 |

ayushaggarwal821 | 415 |

yogesh_aka_dante | 405 |

blackshadows | 5362 |

Ibrahim Nash | 5244 |

akhayrutdinov | 5111 |

mb1973 | 4976 |

Quandray | 4752 |

Login to report an issue on this page.