Question: Rupeek, Recently Asked Online Assessment Questions | Character Set Count | 29th September 2023
0
Entering edit mode

ADD COMMENTlink 14 months ago Delta 2.9k
0
Entering edit mode
signed callerFunc() {
    //cin>>n;
    string s;
    cin>>s;
    int n = s.size();
    int ans = 0;
    vector<int> res;
    unordered_set<int> st;
    for(int i=0;i<n;i++){
        vector<int> tmp;
        int cur = s[i]-'a',mask=0,m = res.size();
        for(int i =0;i<m;i++){
            if(res[i]!=cur) tmp.push_back(res[i]);
        }
        tmp.push_back(cur);
        m = tmp.size();
        res = tmp;
        for(int j=m-1;j>=0;j--){
            mask|=(1<<res[j]);
            if(st.find(mask)==st.end()){
                ++ans;
                st.insert(mask);
            }
        }
    }
    cout<<ans<<endl;
    return 1;
}

Simple logic : Can only create a unique set of size 26. Brute force a 26*n solution.

ADD COMMENTlink 14 months ago jaskaran • 0
Entering edit mode
0

cool

ADD REPLYlink 14 months ago
warhead
• 0
0
Entering edit mode

cool

ADD COMMENTlink 14 months ago warhead • 0

Login before adding your answer.

Similar Posts
Loading Similar Posts