Timer is Running

Maximum difference Indexes
##### Submissions: 2425   Accuracy: 50.1%   Difficulty: Easy   Marks: 2

Given an array of size n with possibly duplicate elements. Consider differences between first and last occurrences of all elements and find the maximum such difference.  Note that if any element appears only once, then the difference for the element is 0.

Input:
First line consists of T test cases. First line of every test case consists of N, denotes the element in an array. Second line consists of elements in Array.

Output:
Print the Maximum Difference. If no two distinct element is present then print 0.

Constraints:
1<=T<=100
1<=N<=1000
1<=Ai<=1000

Example:
Input:

1
9
2 1 3 4 2 1 5 1 7
Output:
6

Explanation:
For the above test case: Element 1, index 1 and 7. Maximum difference 6.

#### ** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Saksham Raj Seth
Author: saksham seth

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.