All problems
0910EasyHash TableString

Letters Stamped Both Ways

Tracked in this browser only
Write code

Trains the technique from

LeetCode 3120Count the Number of Special Characters I

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

A plate reads word, a mix of lowercase and uppercase English letters.

A letter of the alphabet is stamped both ways when the plate holds it in lowercase somewhere and in uppercase somewhere. Return how many letters of the alphabet are stamped both ways.

Examples

Example 1

Input
word = "kEttLeKnObs"
Output
2

The letter k appears as both k and K, and the letter e appears as both e and E. The letters l, o, t, n, b and s appear in only one case each.

Example 2

Input
word = "mMnNoOpPqQ"
Output
5

All five letters turn up in both cases.

Example 3

Input
word = "abcdefghij"
Output
0

Nothing on the plate is uppercase, so no letter is stamped both ways.

Constraints

  • 1 <= word.length <= 50
  • word consists of lowercase and uppercase English letters only

The signature

The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def number_of_special_chars(word: str) -> int:
Java
public int numberOfSpecialChars(String word)
September 7
Apply