You are given 2 arrays $A, B$ both of $n$ integers, find the longest common subsequence (LCS) of $A$ and $B$.
In other words, find the largest $k$ that there exist some indices $i_1 < i_2 < … < i_k$ and $j_1 < j_2 < … < j_k$ that: $$A_{i_1} = B_{j_1}$$ $$A_{i_2} = B_{j_2}$$ $$…$$ $$A_{i_k} = B_{j_k}$$
Input:
4
1 2 3 4
3 4 2 1
Output:
2
Note: The LCS is $(3, 4)$.