Given two strings x and y, compute the maximum length of a string s such that:
s
is a
subsequence
of
x
(can delete zero or more characters from
x
without reordering the remaining characters), and
s
is a
substring
of
y
(must appear as a contiguous block in
y
).
Return the maximum possible length.
x = "abcd"
,
y = "abdc"
"abd"
(subsequence of
x
, substring of
y
), so the answer is
3
.
x = "hackerranks"
,
y = "hackers"
7
(because
"hackers"
is a subsequence of
x
and also a substring of
y
).