Given an array. Write a program to calculate the sum of lengths of contiguous subarrays having all distinct elements.
Input:
First line of input contains a single integer T which denotes the number of test cases. Then T test cases follows. First line of each test case contains a single integer N which denotes the number of elements in the array. Second line of each test case contains N space separated integers.
Output:
For each test case, print the sum of lengths of contiguous subarrays having all distinct elements.
Constraints:
1<=T<=100
1<=N<=105
Example:
Input:
3
3
1 2 3
3
1 2 1
4
1 2 3 4
Output:
10
7
20
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.
bruceewayne | 119 |
rajupraaa1234 | 110 |
SUZAKU | 104 |
yash_sharan | 104 |
Core_Ka_Bachha | 99 |
mr_kksparrow | 433 |
manvirag982 | 302 |
rajupraaa1234 | 245 |
Exception_404 | 244 |
snow_den_ | 236 |
blackshadows | 5331 |
Ibrahim Nash | 5219 |
akhayrutdinov | 5111 |
mb1973 | 4929 |
Quandray | 4567 |