👍💯🔥100% BEATS NO BUILT_IN FUNCTIONS 👍💯🔥
Intuition\nThe function aims to find the character in a string s that appears as both uppercase and lowercase. The character with the highest ASCII value (appea
# Intuition\nThe function aims to find the character in a string s that appears as both uppercase and lowercase. The character with the **highest ASCII value (appearing last alphabetically)** among such characters is considered the "greatest."\n\n# Approach\nCharacter Counts:\n\n*Two integer arrays uc (uppercase counts) and lc (lowercase counts) are created, both of size 26 (representing the 26 letters in the alphabet).*\nThe code iterates through each character i in the string s.\n - If i is lowercase (between \'a\' and \'z\'), it increments the corresponding count in lc.\n- If i is uppercase (between \'A\' and \'Z\'), it increments the count in uc (accounting for the ASCII offset between uppercase and lowercase).\nFinding the Greatest Character:\n\n*A character variable max is initialized with -1 (indicating no character found yet).*\nThe code iterates through the uc and lc arrays (0 to 25).\n- If a character appears in both uc[i] (uppercase count) and lc[i] (lowercase count), it means the character appears in both cases.\n- The ASCII value of the character (i) is compared with the current max.\n- If the current character\'s value (i) is greater than max, it becomes the new max. This ensures we find the character with the highest ASCII value (latest alphabetically).\nReturning the Result:\n\n*A string res is initialized as empty.*\n- If a character was found (max is not -1), the character is converted back to its uppercase form by adding 65 (offset between \'a\' and \'A\') and appended to res.\n- The function returns the res string, which will either be empty (no character found) or contain the "greatest" character.\n\n# Complexity\n- Time complexity:\n**O(n)**\n\n- Space complexity:\n**O(n)**\n\n# Code\n```\nclass Solution {\npublic:\n    string greatestLetter(string s) {\n        int uc[26]={0},lc[26]={0};\n        for(auto i:s){\n            if(i >= \'a\' && i <= \'z\'){\n                lc[i - \'a\']++;\n            }\n            else if(i >= \'A\' && i <= \'Z\'){\n                uc[i - \'A\']++;\n            }\n        }\n        char max = -1;\n        for(int i=0;i<26;i++){\n            if(uc[i] && lc[i]){\n                if(max < i){\n                    max = i;\n                }\n            }\n        }\n        string res = "";\n        if(max != -1){\n            res += max + 65;\n        }\n        return res;\n    }\n};\n```
['C++']