class Solution {
public:
    int FirstNotRepeatingChar(string str) {
        unordered_map<char,int>m_firstpos;
        unordered_map<char,int>m_nums;
        for(int i=0;i<str.size();i++){
            char c=str[i];
            if(!m_nums.count(c)){
                m_firstpos[c]=i;m_nums[c]=1;
            }
            else{
                m_nums[c]++;
            }
        }
        int minpos=str.size();
        for(auto it=m_nums.begin();it!=m_nums.end();it++){
            if(it->second==1){
                minpos=min(minpos,m_firstpos[it->first]);
            }
        }
        if(minpos!=str.size())return minpos;
            
        return -1;
    }
};