Following their hints


Remember to check !q.empty() before calling q.front() or q.pop()!

//Create a count array of size 26 (assuming only lower case characters are present)
//  and initialize it with zero.
//Create a queue of char datatype.
//Store each character in queue and increase its frequency in the hash array.
//For every character of stream, we check front of the queue.
//If the frequency of character at the front of queue is one,
//  then that will be the first non repeating character.
// else if frequency is more than 1, then we pop that element.
// If queue became empty that means there are no non repeating character
//   so append #.
string Solution::solve(string A) {
    string result;
    vector<int> charCount = vector<int>(26, 0);
    queue<char> q;
    for (char ch : A) {
        if (charCount[ch-'a'] <= 1) {
        while (!q.empty() && charCount[q.front()-'a'] > 1) {
        if (q.empty())
            result += '#';
            result += q.front();
    return result;


Nicely done. Thanks!