Longest common subsequence of two event logs
Asked at Two Sigma
Two systems each write an ordered log of order-state codes. Network hiccups drop some entries, so the logs differ, but the events that did land arrive in the same relative order in both. To measure how much they agree you want the longest common subsequence (LCS): the longest string of codes that appears in both, in order, not necessarily contiguously.
a = "ABCBDAB", b = "BDCAB"
-> 4 # e.g. "BCAB" appears in order in both
Return the length of the longest common subsequence. Target time and space.
Show a hint
Line the two strings up as a grid. If the last characters match, they can both be spent on one shared symbol. If not, you must drop the last character of one string or the other.
Your answer
This one is open-ended. Work it through, then check your reasoning against the full solution.