Easy to understand solution | Explained
We need to find english letters occurring both upper and lower case.\nLet\'s use a set do mark letters that we have seen.\n\nIf we are currently looking at a lo
We need to find english letters occurring both upper and lower case.\nLet\'s use a set do mark letters that we have seen.\n\nIf we are currently looking at a lower case letter, we will check if the upper case counterpart was already seen, if it was then we will consider it by\ncomparing with the greatest letter found so far.\n\nSame logic for smaller case letters, just we compare against the upper case format, since the question asks for upper case.\n\nTime complexity: `O(n)` since we traverse the string s once.\nSpace complexity: `O(n)` for the set seen.\n\n# Code\n\n```\nclass Solution:\n    def greatestLetter(self, s: str) -> str:\n        MAX = float(\'-inf\')\n        greatest = ""\n        seen = set()\n        \n        for c in s:\n            if not c.isalpha(): continue\n            cur_letter_ordinal = ord(c)\n                \n            # We are dealing with upper case letter\n            if 65 <= cur_letter_ordinal < 97:  \n                _lower_case_ordinal = cur_letter_ordinal + 32\n                if chr(_lower_case_ordinal) in seen:\n                    if cur_letter_ordinal > MAX:\n                        greatest = c\n                        MAX = cur_letter_ordinal\n            \n            # dealing with lower case\n            else:\n                _upper_case_ord = cur_letter_ordinal - 32\n                if chr(_upper_case_ord) in seen:\n                    if _upper_case_ord > MAX:\n                        greatest = chr(_upper_case_ord)\n                        MAX = _upper_case_ord\n            \n            \n            seen.add(c)\n        \n        return greatest\n```\t
[]