Leetcode 3120: Count the Number of Special Characters I

grid47
grid47
Exploring patterns and algorithms
Dec 31, 2023 5 min read

You are given a string word. A letter is considered special if it appears both in its lowercase and uppercase form in the string. Return the number of special letters in word.
Problem
Approach
Steps
Complexity
Input: The input consists of a string `word` of length n.
Example: word = "aAAbcdBC"
Constraints:
• 1 <= word.length <= 50
• word consists of only lowercase and uppercase English letters
Output: Return the number of special letters in the string `word`.
Example: Output: 3
Constraints:
Goal: Identify letters that appear in both lowercase and uppercase in the string and count them.
Steps:
• 1. Create a set to store unique characters in `word`.
• 2. Loop through each letter in the alphabet ('a' to 'z').
• 3. For each letter, check if both the lowercase and uppercase forms exist in the set.
• 4. Count and return the total number of special letters.
Goal: The problem constraints define the limits on the length and content of the string.
Steps:
• 1 <= word.length <= 50
• word consists of only lowercase and uppercase English letters
Assumptions:
• The input string will only contain lowercase and uppercase English letters.
• The string will have a length between 1 and 50 characters.
Input: word = "aAAbcdBC"
Explanation: The special characters are 'a', 'b', and 'c', as they appear in both uppercase and lowercase in `word`.

Input: word = "abcdef"
Explanation: No special characters exist in this string, as no letter appears in both uppercase and lowercase.

Input: word = "AbBcC"
Explanation: The special characters are 'b' and 'c', as they appear both in lowercase and uppercase.

Link to LeetCode Lab


LeetCode Solutions Library / DSA Sheets / Course Catalog
comments powered by Disqus