Count the Number of Special Characters II

You are given a string word. A letter c is called special if it appears both in lowercase and uppercase in word, and every lowercase occurrence of c appears before the first uppercase occurrence of c.

Return the number of special letters in word.

Example 1
Inputword = "aaAbcBC"
Output3
The special characters are 'a', 'b', and 'c'.
Example 2
Inputword = "abc"
Output0
There are no special characters in word.

Constraints

  • 1 <= word.length <= 2 * 10^5
  • word consists of only lowercase and uppercase 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