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.
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.
Print the Maximum Difference. If no two distinct element is present then print 0.
2 1 3 4 2 1 5 1 7
For the above test case: Element 1, index 1 and 7. Maximum difference 6.
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.