Given a string s, the task is to find the number of possible non-empty sequences of letters that can be made.
Input: "AAB" Output: 8 Explanation: 1) A 2) AA 3) AAB 4) AB 5) ABA 6) B 7) BA 8) BAA Total 8 possibilities Input: "AAABBC" Output: 188
There are two possibilities either take the current character to our answer or leave it. We can solve this problem
To check for duplicates we can take set as a data Structure and will put our answers there and our count will be the size of our set.
Below is the implementation of the above approach:
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Count of sub-sequences which satisfy the given condition
- Count all sub-sequences having product <= K - Recursive approach
- Count pairs of parentheses sequences such that parentheses are balanced
- Count sequences of length K having each term divisible by its preceding term
- Count distinct regular bracket sequences which are not N periodic
- Find if it is possible to make a binary string which contanins given number of "0", "1" , "01" and "10" as sub sequences
- Check if two same sub-sequences exist in a string or not
- Number of sub-sequences of non-zero length of a binary string divisible by 3
- Print all increasing sequences of length k from first n natural numbers
- Print all non-increasing sequences of sum equal to a given number x
- Find all even length binary sequences with same sum of first and second half bits
- Print all longest common sub-sequences in lexicographical order
- Mutual Recursion with example of Hofstadter Female and Male sequences
- Print all sequences starting with n and consecutive difference limited to k
- Distinct strings such that they contains given strings as sub-sequences
- Count of binary strings of length N having equal count of 0's and 1's and count of 1's ≥ count of 0's in each prefix substring
- Check if count of Alphabets and count of Numbers are equal in the given String
- Count ways to split a Binary String into three substrings having equal count of zeros
- Count subsequences in first string which are anagrams of the second string
- Find the count of palindromic sub-string of a string in its sorted form
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : mohit kumar 29