- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Program to find number of string we can make where 'a' can be 'a' or 'b', and 'b' remains 'b'in Python

Suppose we have a string s with only "a" and "b". "a"s can stay "a" or turn into "b", but "b"s can not be changed. We have to find the number of unique strings that we can make.

So, if the input is like s = "baab", then the output will be 4, as We can make these strings − ["baab", "babb", "bbab", "bbbb"]

To solve this, we will follow these steps −

- counts := frequency of 'a' in s
- return 2^counts

Let us see the following implementation to get better understanding −

## Example

class Solution: def solve(self, s): counts = s.count('a') total = 2**(counts) return total ob = Solution() print(ob.solve("baab"))

## Input

"baab"

## Output

4

- Related Questions & Answers
- Larger of a^b or b^a in C++
- Check if a number can be expressed as a^b in Python
- Find FIRST & FOLLOW for the following Grammar. S → A a A | B b B A → b B B → ε
- Check if a number can be expressed as a^b in C++
- Python a += b is not always a = a + b
- Find multiple of x closest to or a ^ b (a raised to power b) in C++
- Find a palindromic string B such that given String A is a subsequence of B in C++
- Count number of pairs (A <= N, B <= N) such that gcd (A , B) is B in C++
- Show that the following grammar is LR (1) S → A a |b A c |B c | b B a A → d B → d
- Program to find minimum number of characters to be deleted to make A's before B's in Python
- Program to find N-th term of series a, b, b, c, c, c…in C++
- Maximum elements which can be crossed using given units of a and b in C++
- How I can check if A is superclass of B in Python?
- Program to find Nth term divisible by a or b in C++
- Minimum Flips to Make a OR b Equal to c in C++

Advertisements