Count number of equal pairs in a string
Submissions: 326   Accuracy:

36.23%

  Difficulty: Basic   Marks: 1

Given a string s, find the number of pairs of characters that are same. Pairs (s[i], s[j]), (s[j], s[i]), (s[i], s[i]), (s[j], s[j]) should be considered different.

INPUT: The first line consists of an integer T i.e. the number of test cases. Each test case has the single line input, denoting the string s.

OUTPUT: Print the total number of pairs in the string.

CONSTRAINTS:
1<=T<=100
1<=|Length of string|<=105

EXAMPLES:
INPUT :

2
air
geeksforgeeks

OUTPUT : 
3
31

EXPLANATION:

Input: air
Output: 3
Explanation :
3 pairs that are equal are (a, a), (i, i) and (r, r)

Input : geeksforgeeks
Output : 31

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

Author: saksham0751


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.