Given a string which consists of only 0, 1 or 2s, count the number of substring which have equal number of 0s, 1s and 2s.
Examples:
Input : str = “0102010”
Output : 2
Explanation : Substring str[2, 4] = “102” and
substring str[4, 6] = “201” has
equal number of 0, 1 and 2
Input : str = "102100211"
Output : 5
Input:
The first line of input contains a single integer T denoting the number of test cases. Then T test cases follow. Each test case consists of one line. The line contains a string of 0's, 1's and 2's.
Output:
Corresponding to each test case, in a new line, print the count all possible substrings that have same number of 0s, 1s and 2s.
Constraints:
1 ≤ T ≤ 100
1 ≤ string length ≤ 1000
Example:
Input
2
0102010
102100211
Output
2
5
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 | 175 |
manvirag982 | 158 |
Core_Ka_Bachha | 137 |
yash_sharan | 136 |
rajupraaa1234 | 133 |
mr_kksparrow | 433 |
manvirag982 | 374 |
rajupraaa1234 | 268 |
Exception_404 | 254 |
PranathiBhuvanagiri | 242 |
blackshadows | 5331 |
Ibrahim Nash | 5219 |
akhayrutdinov | 5111 |
mb1973 | 4929 |
Quandray | 4567 |