Beats 100% Using Frequency Array in C++
IntuitionI need to store the lower case letter as well as upper case letter into two arrays respectively. Then find both upper case and lower case are present i
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
I need to store the lower case letter as well as upper case letter into two arrays respectively. Then find both upper case and lower case are present in the string or not.

# Approach
<!-- Describe your approach to solving the problem. -->
Now after storing frequencies of both case into two separate arrays now we will run a loop for 26 letters. In the loop we will check from the last letter to first letter using index and we will check if the same index of two arrays contains value greater than 0 or not. If same index of both arrays have the positive value we will take it as a output of the function else we will return empty string as a output of the function.

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
### O(n):
Where n is the length of the string and another loop will run 26 times to find the both upper case or lower case present or not.

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
### O(1):
As we are taking two arrays of constant size which is 26.

# Code
```cpp []
class Solution {
public:
    string greatestLetter(string s) {
        string ans = "";
        vector<int>freqUpper(26,0);
        vector<int>freqLower(26,0);

        for(int i=0;i<s.size();i++){
            // Check lower case letter
            int index;
            if(s[i] >= 'a' && s[i] <= 'z'){
                index = int(s[i] - 'a');
                freqLower[index]++;
            }
            // Check upper case letter
            else{
                index = int(s[i] - 'A');
                freqUpper[index]++;
            }
        }
        // check from the last to find both upper and lower case exits or not 
        for(int i=25;i>=0;i--){
            if(freqUpper[i] > 0 && freqLower[i] > 0){
                ans = char(i + 'A');
                break;
            }
        }
        return ans;
    }
};
```
['C++']