class Solution {
public:
    int FirstNotRepeatingChar(string str) {
      if (str.empty()) {
        return -1;
      }
      
      int res = -1;
      std::unordered_map<char, int> count;
      
      for (int i = 0; i < str.size(); ++i) {
        ++count[str[i]];
      }
      
      for (int i = 0; i < str.size(); ++i) {
        if (count[str[i]] == 1) {
          res = i;
          break;
        }
      }
      
      return res;
    }
};