LeetCode 1143 Longest Common Subsequence - Why Naive Fails

The trap

Generate all subsequences of text1 and check which appear in text2.

A string of length mm has 2m2^m subsequences. Checking each in text2 takes O(n)O(n) time.

Total: O(n2m)O(n \cdot 2^m). Way too slow.