LeetCode 3120

Count the Number of Special Characters I

Concepts:

String
Hashmap

Description: 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.

Optimal Approach

Use two boolean arrays of length 26 for lowercase and uppercase letters. Scan the word once, marking each letter in the appropriate array. Count indices where both arrays are true for the same letter.

Time: O(n)

Space: O(1)

All Problems