Leetcode 2309: Greatest English Letter in Upper and Lower Case

grid47
grid47
Exploring patterns and algorithms
Mar 21, 2024 4 min read

Given a string s consisting of both uppercase and lowercase English letters, return the greatest letter that appears as both a lowercase and uppercase letter in the string. The returned letter should be in uppercase. If no such letter exists, return an empty string.
Problem
Approach
Steps
Complexity
Input: The input consists of a string s containing both uppercase and lowercase English letters.
Example: s = 'aBcDeFg'
Constraints:
• 1 <= s.length <= 1000
• s consists of lowercase and uppercase English letters.
Output: Return the greatest English letter that appears as both a lowercase and uppercase letter, in uppercase form. If no such letter exists, return an empty string.
Example: For s = 'aBcDeFg', the output is 'F'.
Constraints:
• Return the greatest letter in uppercase.
Goal: The goal is to find the letter that appears both in uppercase and lowercase, and return the greatest one in uppercase.
Steps:
• Iterate through the string s and track the occurrence of each letter in both lowercase and uppercase.
• Start from the greatest possible letter ('Z') and check if both the lowercase and uppercase versions are present in the string.
• Return the first such letter found in uppercase, or an empty string if no such letter exists.
Goal: The problem constraints ensure that the string is manageable in size and contains only English letters.
Steps:
• 1 <= s.length <= 1000
• s consists of lowercase and uppercase English letters.
Assumptions:
• The input string contains only English letters and may include both uppercase and lowercase versions of letters.
Input: s = 'aBcDeFg'
Explanation: The letter 'F' is the greatest letter that appears as both 'f' and 'F'. The function returns 'F'.

Link to LeetCode Lab


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