- 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 subsequences with i, j and k number of x, y, z letters in Python

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

## Example

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"))

## Input

"xxyz"

## Output

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
- Program to find number of consecutive subsequences whose sum is divisible by k in Python
- Find number of pairs (x, y) in an array such that x^y > y^x in C++
- Find the Number of solutions for the equation x + y + z <= n using C++
- Program to find number of pairs (i, j) such that ith and jth elements are same in Python
- Program to find number of arithmetic subsequences from a list of numbers in Python?
- Find larger of x^y and y^x in C++
- Find x, y, z that satisfy 2/n = 1/x + 1/y + 1/z in C++
- 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 max number of K-sum pairs 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

Advertisements