MongoDB interview question

Longest Common Subsequence optimised solution.