You are not logged in. Please login at www.codechef.com to post your questions!

×

String question

https://www.hackerrank.com/contests/seriea/challenges/limak-and-weird-subsequences Can anyone give me some hint of this question?? Contest not running..

asked 14 Jun '18, 00:29

sna902055's gravatar image

5★sna902055
425
accept rate: 7%

edited 14 Jun '18, 00:30


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[i];
    }


        if(temp[0]==temp[temp.size()-1]) ans++;

}
link

answered 14 Jun '18, 01:37

soham1234's gravatar image

6★soham1234
1.8k614
accept rate: 22%

Got it..... thank you...

(14 Jun '18, 06:28) sna9020555★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×643

question asked: 14 Jun '18, 00:29

question was seen: 97 times

last updated: 14 Jun '18, 06:28