can anyone plzz tell my mistake in my program… it is working correct in code compile and run … CodeChef: Practical coding for everyone
1 Like
You have not understood this Question correctly. Actually we have to calculate only such no of characters that are different from neighbours.
For example,
Your answer for test case “aba” is 4. But right answer is 8.
2 Likes
First we need to find the set of characters in the string which are not same as their neighbouring characters. Then we need to find all the subsets of that set.
So if the number of elements in the set is N then the number of subsets is 2^N.
As N is small (1 ≤ N ≤ 50) so simple brute force would work. Though I have implemented Modular Exponentiation which has a complexity of O(log(N)).
6 Likes