Twin Strings
Practice
3.4 (5 votes)
Basic programming
Basics of bit manipulation
Bit manipulation
Problem
36% Success 1146 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

You are given a string \(S\) of length \(N\). A string is called twin if the characters of the string can be split into two groups such that the occurrence of each character is equal in both groups.

Find the number of twin substrings of \(S\).

Input Format:

  • The first line contains an integer \(T\), denoting the number of test cases.
  • The first line of each test case contains an integer \(N\), denoting the length of the string \(S\).
  • The second line of each test case contains the string \(S\).

Output Format:

For each test case, print the number of twin substrings of \(S\).

Constraints:

\(1 <= T <= 10\)

\(1 <= N <= 10^5\)

\(S \) contains lower-case English letters

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

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
17 votes
Tags:
ApprovedBasic ProgrammingBit manipulationMathMedium
Points:30
6 votes
Tags:
Basic ProgrammingBit ManipulationBasics of Bit ManipulationAlgorithmsGreedy AlgorithmsBit manipulation
Points:30
15 votes
Tags:
AlgorithmsApprovedBit manipulationMediumOpen