Last Updated: 13 Oct, 2025

Maximum Dish Selection

Moderate

Problem statement

Ramu has N dishes of different types arranged in a row, represented by an array A, where A[i] denotes the type of the i-th dish. He wants to choose the maximum possible number of dishes, but he must adhere to two conditions:


1) He can only choose dishes of a single type.


2) No two chosen dishes can be adjacent to each other in the original row.


Your task is to determine which type of dish Ramu should choose to maximize his collection. If there's a tie (i.e., he can achieve the same maximum count with multiple dish types), he will choose the dish type with the smallest numerical value.


Input Format:
The first line contains an integer T, the number of test cases.

For each test case:
  The first line contains a single integer N, the number of dishes.
  The second line contains N space-separated integers, A1, A2, ..., AN, representing the types of the dishes.


Output Format:
For each test case, print a single line containing one integer — the type of dish that Ramu should choose.


Note:
An element from array 'a' and an element from array 'b' can be part of only one pair. Once used, they cannot be used again to form another pair.