
You have two delivery drivers who each have a pickup plan represented as a list of restaurant IDs (strings).
Because there is only one car, the combined route can only visit restaurants that both drivers need to pick up from. The route must also respect the original order of restaurants for each driver (i.e., once you move forward in a driver’s list, you cannot go back).
Your task is to compute the longest possible list of restaurants that can be visited under these constraints.
Formally, given two sequences driver1 and driver2, return a sequence that is the longest common subsequence (LCS) of the two lists.
driver1
: list of strings, length
n
driver2
: list of strings, length
m
driver1 = ["A","B","C","D"]
driver2 = ["B","C","E"]
A valid output is ["B","C"].
0 <= n, m <= 2000
(adjust if needed)