Greatest English Letter in Upper and Lower Case LeetCode solution in C++
1class Solution {2public:3string greatestLetter(string s) {4vector<int> low(26),5upp(26); // storing occurences of lower and upper case letters6string res = "";78for (auto it : s) // iterate over each char and mark it in respective vector9{10if (it - 'A' >= 0 && it - 'A' < 26)11upp[it - 'A']++;12else13low[it - 'a']++;14}1516for (int i = 25; i >= 0; i--) // start from greater char17{18if (low[i] && upp[i]) // if char found in upp and low that will be the result19{20res += 'A' + i;21break;22}23}24return res;25}26};