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).
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.
- Longest Subsequence of a String containing only vowels
- Longest Increasing Subsequence using Longest Common Subsequence Algorithm
- Lexicographically smallest K-length substring containing maximum number of vowels
- Maximum length subsequence such that adjacent elements in the subsequence have a common factor
- Minimum cost to make Longest Common Subsequence of length k
- Length of longest common prime subsequence from two given arrays
- Longest Ordered Subsequence of Vowels
- Longest subsequence consisting of alternate vowels and consonants
- Minimize length of Substrings containing at least one common Character
- Longest Subsequence of a String containing only Consonants
- Find the number of words of X vowels and Y consonants that can be formed from M vowels and N consonants
- Length of longest Palindromic Subsequence of even length with no two adjacent characters same
- Longest Common Subsequence | DP-4
- Printing Longest Common Subsequence
- Longest Common Increasing Subsequence (LCS + LIS)
- Printing Longest Common Subsequence | Set 2 (Printing All)
- Longest common subsequence with permutations allowed
- LCS (Longest Common Subsequence) of three strings
- C++ Program for Longest Common Subsequence
- Java 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.