How does the longest common subsequence problem use DP?
LeetCode Patterns Flashcards: Dynamic Programming, Memoization, Tabulation, Patterns
Аудио-карточка · 0:28Nortren·
How does the longest common subsequence problem use DP?
0:28
Compare two strings to find the longest sequence of characters appearing in both in the same order but not necessarily contiguous. The state is the current position in each string, forming a two-dimensional table. If characters at both positions match, the answer is one plus the result for both positions advanced by one. If they do not match, take the maximum of advancing either position alone. The base case is zero when either string is exhausted. Fill the table bottom-up or right-to-left. This runs in O of m times n time and space.
neetcode.io