Challenge: First Unique Letter

Lab C++ Beginner 10 points

Read a word and print the first letter that appears only once, or none.

Input

One word (lowercase letters).

Output

A letter, or none.

Example

Input

leetcode

Output

l
Sample input available Sample output available
Editor
C++

Hints

First count every letter.

Then walk the word again and stop at the first letter with count 1.

Solution explanation

Two passes: O(n).

Show solution
#include <iostream>
#include <string>
using namespace std;

int main() {
    string s;
    cin >> s;
    int count[26] = {0};
    for (char c : s) count[c - 'a']++;
    for (char c : s) {
        if (count[c - 'a'] == 1) {
            cout << c << endl;
            return 0;
        }
    }
    cout << "none" << endl;
    return 0;
}
Output
Answer
HOME LABS COMMUNITY DASHBOARD