String question


Can anyone give me some hint of this question??
Contest not running…

The problem basically asks you are given a string, if you can choose a subset of characters such that when taken in same order as present in the main string they have same beginning and end character.
This can be easily solved using bitmasking. I won’t explain much. If you want you can have a look at my code. If you don’t know bitmasking learn it and then attempt this.

 for(int mask=0;mask<(1ll<<n);mask++)
{
    if(mask==0) continue;
       string temp="";
    loop(i,0,n)
    {
        if(mask&(1ll<<i)) temp+=s*;
    }
    
    
        if(temp[0]==temp[temp.size()-1]) ans++;
    
}

Got it… thank you…