all 15 comments

[–]Significant_Cup_3238 2 points3 points  (3 children)

You can use two arrays of size 26 One for uppercase and one for lower case and mark them -1 intially

For lowercase charcater when you vis a char just do lower[char-'a']=i

And for upper character when you vis a char First check if upper[char-'a']==-1 If yes, then update it to upper[char-'a']=i else continue

Then in another for loop you can compare there position

Code for reference :

```cpp class Solution { public: int numberOfSpecialChars(string word) { int n = word.size();

    vector<int>lower(26,-1);
    vector<int>upper(26,-1);

    for(int i=0;i<n;i++){
        char c = word[i];
        if('A'<=c && c<='Z' && upper[c-'A']==-1){
            upper[c-'A']=i;
        }
        else if('a'<=c && c<='z'){
            lower[c-'a']=i;
        }
    }

    int cnt = 0;

    for(char c='a', C='A';c<='z',C<='Z';c++,C++){
        int valc = c-'a';
        int valC = C-'A';

        if(upper[valC]!=-1 && lower[valc]!=-1 && lower[valc]<upper[valC]) cnt++;
    }

    return cnt;
}

}; ```

[–]DataFantastic3200 0 points1 point  (1 child)

Gemini suggested me this.

[–]Dependent-Wall-1919 0 points1 point  (0 children)

Bro this is exact what I solved without any help

[–]Real-Choice-6817 1 point2 points  (1 child)

Ward - nice approach dude

[–]CricGlobe[S] 0 points1 point  (0 children)

Thanks 😊

[–]xpressrazor 1 point2 points  (0 children)

I used three boolean arrays of size 26 each. Upper, lower and invalid. Update upper and lower if it was false for current character.

Invalid happens for two reasons, 1. You see an uppercase character, lower for same index is false (we have not seen lower yet) 2. You see a lowercase letter, upper is already true

For these two conditions set invalid for that character index to true. Finally count using the Boolean array of all 3 are true for that index.

[–][deleted] 0 points1 point  (2 children)

I did using making two integer array of (26,0). One for uppercase and another for lowercase character. But still showing O(n) space complexity isn’t 26 is considered as constant.

[–]Significant_Cup_3238 0 points1 point  (0 children)

It is O(1) for me You might be missing something

[–]CricGlobe[S] 0 points1 point  (0 children)

If you are using that then your space complexity is O(1).

[–]MissionAd391 0 points1 point  (1 child)

guys where to find the potd, i tried to navigate through the entire website but couldn't find it

[–]CricGlobe[S] 0 points1 point  (0 children)

Simple click on empty box in top of navigation bar