Given two strings X and Y of length m and n respectively. The problem is to find the length of the longest common subsequence of strings X and Y which contains all vowel characters.
Input : X = "aieef" Y = "klaief" Output : aie Input : X = "geeksforgeeks" Y = "feroeeks" Output : eoee
Naive Approach: Generate all subsequences of both given sequences and find the longest matching subsequence which contains all vowel characters. This solution is exponential in term of time complexity.
Efficient Approach (Dynamic Programming): This approach is a variation to Longest Common Subsequence | DP-4 problem. The difference in this post is just that the common subsequence characters must all be vowels.
Length of LCS = 3
Time Complexity: O(m*n).
Auxiliary Space: O(m*n).
- Minimum cost to make Longest Common Subsequence of length k
- Longest Ordered Subsequence of Vowels
- Longest Common Subsequence | DP-4
- Longest Common Anagram Subsequence
- LCS (Longest Common Subsequence) of three strings
- Printing Longest Common Subsequence
- Longest Common Subsequence | DP using Memoization
- C++ Program for Longest Common Subsequence
- Longest Common Increasing Subsequence (LCS + LIS)
- Longest Common Subsequence with at most k changes allowed
- Longest common anagram subsequence from N strings
- Java Program for Longest Common Subsequence
- Longest Subsequence with at least one common digit in every element
- Edit distance and LCS (Longest Common Subsequence)
- Python Program for Longest Common Subsequence
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.