DEV Community

loading...

Discussion on: Daily Challenge #259 - Duplicate Encoder

Collapse
vidit1999 profile image
Vidit Sarkar

Here is a C++ solution,

string encodeDuplicate(string s){
    // stores the count of corresponding character (lower cased) in s
    unordered_map<char, int> charCount;

    for(char c : s) charCount[tolower(c)]++;

    string ans = "";

    for(char c : s) ans += (charCount[tolower(c)] > 1)? ')' : '(';

    return ans;
}