 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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
Advertisements
 