Sum of distinct elements for a limited range
Submissions: 1674   Accuracy:

50.74%

  Difficulty: Basic   Marks: 1

Given an array of n elements such that every element of array is an integer in the range 1 to n, find the sum of all the distinct elements of the array.

Input:
First line consists of T test cases. First line of every test case consists of N. Second line of every test case consists of elements of Array.

Output:
Single line output, print the sum of distinct element of array.

Constraints:
1<=T<=200
1<=N<=10^4

Example:
Input:

2
5
1 2 3 3 4
5
1 1 1 2 2
Output:
10
3

** 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.



Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.