Write longest_common_subsequence(text1: str, text2: str) -> int: the length of the longest string that is a subsequence of both inputs. A subsequence keeps some characters in their original order, not necessarily next to each other. Return 0 if nothing is shared.
Examples:
longest_common_subsequence("stone", "longest") == 3("one")longest_common_subsequence("abc", "cba") == 1longest_common_subsequence("xyz", "pqr") == 0
Constraints: each string has 1 to 1000 lowercase letters.
⭐ Bonus: a speed test with two 600-letter strings earns a star in O(m·n). Trying subsequences is far too slow for it.
Show hint
compare the answer for prefixes text1[:i] and text2[:j] with the answers for slightly shorter prefixes, depending on whether their last letters are equal.