Count Number of Substrings

You are given a string s consisting of lowercase English letters from 'a' to 'j'.

A substring is considered valid if at most one character occurs an odd number of times in that substring.

Return the total number of valid substrings in s.

A substring is a contiguous, non-empty sequence of characters within a string.

Example 1:

Input: s = "aba"

Output: 4

Explanation: The valid substrings are "a", "b", "a", and "aba". Each contains at most one character with an odd frequency.

Example 2:

Input: s = "aabb"

Output: 9

Explanation: There are 10 substrings in total. The only invalid substring is "ab", where both 'a' and 'b' occur an odd number of times. Hence, the answer is 9.

Now Your Turn!

Pick the correct output for the given input

Input: s = "abca"

Still unsure what the problem is asking ?

Let’s go through a few more examples, step by step, to make it clearer.

Constraints:

  • 1 <= s.length <= 105
  • s consists only of lowercase English letters from 'a' to 'j'.
0
class Solution {
public:
long long countSubstrings(string s) {
// Your code goes here
return 0;
}
};
Test Case

Input:

S