bugfree Icon
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course
interview-course

Leetcode Problem 2309. Greatest English Letter in Upper and Lower Case

2309. Greatest English Letter in Upper and Lower Case

Leetcode Solutions

Using Sets to Find the Greatest Letter Appearing in Both Cases

  • Initialize two empty sets: lowercase_letters and uppercase_letters.
  • Iterate over each character ch in the string s:
    • If ch is a lowercase letter, add it to lowercase_letters.
    • If ch is an uppercase letter, add it to uppercase_letters.
  • Iterate over the uppercase English alphabet in reverse order (from 'Z' to 'A'):
    • Check if the current uppercase letter and its corresponding lowercase letter are present in their respective sets.
    • If both are present, return the current uppercase letter as the result.
  • If no letter is found that meets the criteria, return an empty string.
UML Thumbnail

Brute Force Search for Greatest Letter in Both Cases

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...