Count the Number of Special Characters I - Problem

You are given a string word. A letter is called special if it appears both in lowercase and uppercase in word.

Return the number of special letters in word.

Input & Output

Example 1 — Mixed Case Letters
$ Input: word = "aaAbcBC"
Output: 3
💡 Note: Letters 'a', 'b', and 'c' each appear in both lowercase and uppercase forms
Example 2 — Only Lowercase
$ Input: word = "abc"
Output: 0
💡 Note: All letters are lowercase only, no uppercase versions present
Example 3 — Partial Match
$ Input: word = "abBcab"
Output: 1
💡 Note: Only letter 'b' appears in both cases (lowercase 'b' and uppercase 'B')

Constraints

  • 1 ≤ word.length ≤ 1000
  • word consists of only lowercase and uppercase English letters.

Visualization

Tap to expand
Special Characters: Letters in Both CasesaaAbcBCInput: "aaAbcBC"Letter A✓ Both casesLetter B✓ Both casesLetter C✓ Both casesCount letters appearing in both lowercase and uppercaseResult: 3 special letters
Understanding the Visualization
1
Input String
String with mixed case letters
2
Identify Pairs
Find letters existing in both forms
3
Count Result
Return count of special letters
Key Takeaway
🎯 Key Insight: Use sets to efficiently track which letters appear in both lowercase and uppercase forms
Asked in
Google 15 Microsoft 12
12.5K Views
Medium Frequency
~10 min Avg. Time
245 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen