Find the Greatest Common Letter with Case Sensitivity in a String C++ Set
Intuition\n Describe your first thoughts on how to solve this problem. \n\nThe goal is to find the greatest uppercase letter in a string that also has its corre
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\nThe goal is to find the greatest uppercase letter in a string that also has its corresponding lowercase letter present. My initial thought is to traverse through the string, store the characters in a set for efficient lookup, and then check for the greatest uppercase letter.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n1. First, store all characters from the string in a set to allow O(1) lookup time for checking if a letter exists.\n2. Then, iterate from \'Z\' (the greatest uppercase letter) down to \'A\'.\n3. For each uppercase letter, check if both the uppercase letter and its corresponding lowercase version (by adding 32 to the ASCII value) exist in the set.\n4. If both exist, return the uppercase letter as the result.\n5. If no such letter is found, return an empty string.\n\n# Complexity\n- **Time complexity:**  \n  The time complexity is $$O(n)$$, where $$n$$ is the length of the input string, as we traverse the string once to build the set and then check for the presence of letters.\n\n- **Space complexity:**  \n  The space complexity is $$O(n)$$, as we store the characters from the string in a set.\n\n# Code\n```cpp\nclass Solution {\npublic:\n    string greatestLetter(string s) {\n        set<char> alpha;  \n        for (char c : s) {\n            alpha.insert(c);  \n        }        \n        for (char c = \'Z\'; c >= \'A\'; --c) {\n            if (alpha.count(c) && alpha.count(c + 32)) {  \n                return string(1, c);\n            }\n        }        \n        return ""; \n    }\n};\n```\n
['C++']