Count the Number of Special Characters I
Real-world version: Letters Stamped Both WaysThe statement here is our own: the same inputs, outputs and technique.
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 starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def number_of_special_chars(word: str) -> int:public int numberOfSpecialChars(String word)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 11 test cases: 11 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's