Total Appeal of A String

The appeal of a string is the number of distinct characters found in the string.

  • For example, the appeal of "abbca" is 3 because it has 3 distinct characters: 'a', 'b', and 'c'.

Given a string s, return the total appeal of all of its substrings.

A substring is a contiguous sequence of characters within a string.

Example 1
Inputs = "abbca"
Output28
The total appeal over all substrings of "abbca" is 5 + 7 + 7 + 6 + 3 = 28.
Example 2
Inputs = "code"
Output20
The total appeal over all substrings of "code" is 4 + 6 + 6 + 4 = 20.

Constraints

  • 1 <= s.length <= 10^5
  • s consists of lowercase English letters.

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate