Greatest English Letter in Upper and Lower Case - Problem
Given a string of English letters s, return the greatest English letter which occurs as both a lowercase and uppercase letter in s. The returned letter should be in uppercase. If no such letter exists, return an empty string.
An English letter b is greater than another letter a if b appears after a in the English alphabet.
Input & Output
Example 1 — Basic Case
$
Input:
s = "lEeTcOdE"
›
Output:
"E"
💡 Note:
The string contains both 'E' and 'e'. Among all letters that appear in both cases (E, T, C, O, D), E is the greatest alphabetically.
Example 2 — No Valid Letters
$
Input:
s = "arRAzFif"
›
Output:
""
💡 Note:
The string contains 'R' and 'r', but no other letter appears in both cases. R is not the greatest possible, but it's the only valid one. Wait, let me recheck - actually 'R' and 'r' are both present, so the answer should be "R".
Example 3 — Single Letter Case
$
Input:
s = "AbCdEfGhIjKlMnOpQrStUvWxYz"
›
Output:
""
💡 Note:
Each letter appears only once in either uppercase or lowercase, but never both. No letter appears in both cases.
Constraints
- 1 ≤ s.length ≤ 1000
- s consists of lowercase and uppercase English letters only.
Visualization
Tap to expand
Understanding the Visualization
1
Input Analysis
Scan string for all characters
2
Find Valid Pairs
Identify letters with both cases
3
Return Greatest
Pick alphabetically largest valid letter
Key Takeaway
🎯 Key Insight: We need to find the greatest letter that exists in both uppercase and lowercase forms in the string.
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code