We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
This code may be easier to understand.... And is fairly efficient I would say
intmain(){strings;cin>>s;intn;cin>>n;vector<bool>a(10e7);for(inti=0;i<s.length();i++)//For every letter in the string{intsum=0;for(intj=0;j<s.length()-i,s[i]==s[i+j];j++)//Runs only as long as the next letter is the samesum+=s[i+j]-96;//Gets the weighta[sum]=true;//Every weight which is present is set as true at those indices}for(inta0=0;a0<n;a0++){intx;cin>>x;//Input required weightif(a[x])cout<<"Yes"<<endl;//If the value at the index is true, that weight is presentelsecout<<"No"<<endl;}return0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Weighted Uniform Strings
You are viewing a single comment's thread. Return to all comments →
This code may be easier to understand.... And is fairly efficient I would say