Count Distinct Subsequences with specific condition
Anonymous User
603

Count distinct non-empty subsequences of a given string

Two strings will be considered same if:

  • Length of string will be same
  • Both contains same set of vowels.

Example: zaye
Subsequences are : { e, y, ye, a, ae, ay, aye, z, ze, zy, zye, za, zae, zay, zaye }
Gourping subsequences wrt above condition:
{
1->z, y (length = 1, vowels = 0)
2-> za, ay (length = 2, vowel set -> {a} for both)
3-> ze, ye (length = 2, vowel set -> {e} for both)
4-> zae, aye (length = 3, vowel set -> {a, e} fro both)
5-> e
6-> a
7-> ae
8-> zy
9->zye
10->zay
11->zaye
}
Explanation : Out of 15 (z & y will be couted as same, za & ay will be same , ze & ye will be same , zae & aye will be counted as same) so remove all those same counting from 15 i.e subtract 4 = 11;

second example: aaaa
Output: 4

Note: Disitinct means you just have to count all those as 1 .

Comments (5)