- 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

Suppose we have a string s with "x", "y" and "z"s, we have to find the number of subsequences that have i number of "x" characters, followed by j number of "y" characters and followed by k number of "z" characters where i, j, k ≥ 1.

So, if the input is like s = "xxyz", then the output will be 3, as we can make two "xyz" and one "xxyz"

To solve this, we will follow these steps:

n := size of s

x := 0, y := 0, z := 0

for i in range 0 to n, do

count := 0

if s[i] is same as "x", then

x := x * 2

x := x + 1

if s[i] is same as "y", then

y := y * 2

y := y + x

if s[i] is same as "z", then

z := z * 2

z := z + y

return z

class Solution: def solve(self, s): n = len(s) x = 0 y = 0 z = 0 for i in range(n): count = 0 if s[i] == "x": x *= 2 x += 1 if s[i] == "y": y *= 2 y += x if s[i] == "z": z *= 2 z += y return z ob = Solution() print(ob.solve("xxyz"))

"xxyz"

3

- Related Questions & Answers
- Program to find number of increasing subsequences of size k in Python
- Program to find number of distinct subsequences in Python
- Program to find number of different subsequences GCDs in Python
- Find number of pairs (x, y) in an array such that x^y > y^x in C++
- Find larger of x^y and y^x in C++
- Program to find number of arithmetic subsequences from a list of numbers in Python?
- Program to count number of flipping required to make all x before y in Python
- Program to find max number of K-sum pairs in Python
- Count number of pairs (i, j) such that arr[i] * arr[j] > arr[i] + arr[j] in C++
- Program to find a pair (i, j) where nums[i] + nums[j] + (i -j) is maximized in Python?
- Program to find number of unique subsequences same as target in C++
- Find maximum sum of triplets in an array such than i < j < k and a[i] < a[j] < a[k] in Python
- Program to find number of subsequences that satisfy the given sum condition using Python
- Python program to calculate the number of digits and letters in a string
- Python program to find list of triplets for which i+j+k is not same as n

Advertisements