Babai and Diti

4.2

4 votes
Problem

Problem

Babai and Diti are fighting for a box of chocolates. Their father decided to give them a simple algorithmic task to decide the winner.

The winner will be the one who solves it first and he/she will win the box of chocolates.

Babai and Diti are given an array of N integers. Each of the integers will be between 0 and 9 (both inclusive ). They have to report the maximum length of subarray with the same first and last integer.

You being Diti's best friend and a programmer need to help her. Babai solves it manually but your program will always beat him. Help Diti win by generating the answer before Babai.

Input :

First line comprises of T the number of test cases. Each test case consists of 2 lines. The first line contains the value of N. The next line consists of N space separated integers, denoting the array of integers father gives to Babai and Diti.

Output :

For every test case, print the answer on a new line denoting the maximum length of subarray with the same first and last integer.

Constraints :

1<=T<=5

1<=N<=100000

0<= Array elements <=9

Problem Setter : Srinivas

Problem Tester : Sandeep

Problem Statement : Sayan

(By IIT Kgp HackerEarth Programming Club)

Time Limit: 2
Memory Limit: 256
Source Limit:
Editor Image

?