Skip to content

Practice Number of Wonderful Substrings

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Medium#1915
LeetCode Problem

Number of Wonderful Substrings

Problem Statement

A wonderful string is a string where at most one letter appears an odd number of times. Given a string word that consists of the first ten lowercase English letters ('a' through 'j'), return the number of wonderful non-empty substrings in word. If the same substring appears multiple times in word, then count each occurrence separately. A substring is a contiguous sequence of characters in a string.

Source: Number of Wonderful Substrings on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
word = "aba"
Output
4

# Example 2

Input
word = "aabb"
Output
9

# Example 3

Input
word = "he"
Output
2

Constraints

1 <= word.length <= 10^5
word consists of lowercase English letters from 'a' to 'j'.

Related LeetCode Problems

Practice more problems similar to Number of Wonderful Substrings.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.