Skip to content

Practice Count the Number of Special Characters II

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

Medium#3121
LeetCode Problem

Count the Number of Special Characters II

Problem Statement

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.

Source: Count the Number of Special Characters II on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
word = "aaAbcBC"
Output
3

# Example 2

Input
word = "abc"
Output
0

# Example 3

Input
word = "AbBCab"
Output
0

Constraints

1 <= word.length <= 2 * 10^5
word consists of only lowercase and uppercase English letters.

Related LeetCode Problems

Practice more problems similar to Count the Number of Special Characters II.

Review your practice with PhantomCodeAI

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