Video courses for company/skill based Preparation
Purchase mock tests for company/skill building
Python program to Count Common Subsequence in two Strings
Count Common Subsequence in two Strings
In this page we will learn how to write a code to count common subsequence in two strings using python. To do this we use Dynamic Programming(DP). Let’s see what is common subsequence means by taking an example.
- string1 = “ABC”
- string2 = “AB”
- common subsequence in “ABC” and “AB” is “A” , “B”, “AB”
- Initialize the variables.
- Accept the inputs.
- Iterate each character from first string .
- Iterate each character from second string.
- Match these characters one by one.
- If they matches store the count.
- Print count.