String operation- long December challenge

Can we do the string operation December challenege qs with this algo

  1. Find all subsets
  2. Store every subset as an array element.
  3. Delete the duplicates
  4. Check all elements with even number of 1s, if reversed, they match an element or not, if they do delete either of them
  5. Count the number of elements
    Print the answer

If yes, please help me implementing it.

We can’t do this for N > 30, as the complexity is simply O(n*2^n).

I implemented the same, sample test case were also passing but giving a wrong answer. So this method is not correct. won’t give you a correct solution.

Will it work for n<10?

Ohh, can u share the code? And u also thought the exact same logic?

It will work for N < 10, but you’ve to change your algorithm. We need not test all the subsets of the string, rather we need to check all the substrings. And moreover simply reversing the substring with even ones is not gonna work, as a string with odd ones can have a substring with even ones. For example (strings 10011 and 10110 has odd ones, but they can be converted into 10011, by reversing the last 3 bits, as they contain even number of ones). You could just look into the editorial for further explanation.

Thanks dude