Finding Pairs
Practice
3.4 (36 votes)
Algorithms
Medium
Sorting
Problem
69% Success 9836 Attempts 30 Points 3s Time Limit 256MB Memory 1024 KB Max Code
Given an array A of N numbers, find the number of distinct pairs (i, j) such that j >=i and A[i] = A[j].
First line of the input contains number of test cases T. Each test case has two lines, first line is the number N, followed by a line consisting of N integers which are the elements of array A.
For each test case print the number of distinct pairs.
Constraints
1 <= T <= 10
1 <= N <= 10^6
-10^6 <= A[i] <= 10^6 for 0 <= i < N
Sample Input
3 4 1 2 3 4 3 1 2 1 5 1 1 1 1 1
Sample Output
4 4 15
Code Editor
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor
Submissions
Please login to view your submissions
Similar Problems
Points:30
3 votes
Tags:
Count sortSortingAlgorithms
Editorial
Login to unlock the editorial
Please login to use the editor
You need to be logged in to access the code editor
Loading...
Please wait while we load the editor