Common Child ⬀
A string is said to be a child of a another string if it can be formed by deleting 0 or more characters from the other string. Letters cannot be rearranged. Given two strings of equal length, what's the longest string that can be constructed such that it is a child of both?
s1 = 'ABCD'
s2 = 'ABDC'
These strings have two children with maximum length 3, ABC and ABD. They can be formed by eliminating either the D or C from both strings. Return 3.
Complete the commonChild function in the editor below.
commonChild has the following parameter(s):
string s1: a stringstring s2: another string
int: the length of the longest string which is a common child of the input strings
There are two lines, each with a string, s1 and s2.
1 ≤ |s1|, |s2| ≤ 5000where|s|means "the length ofs"- All characters are upper case in the range ascii[A-Z].
HARRY
SALLY
2
The longest string that can be formed by deleting zero or more characters from HARRY and SALLY is , whose length is 2.
AA
BB
0
AA and BB have no characters in common and hence the output is 0.
SHINCHAN
NOHARAAA
3
The longest string that can be formed between SHINCHAN and NOHARAAA while maintaining the order is NHA.
ABCDEF
FBDAMN
2
BD is the longest child of the given strings.