LeetCode 115 Distinct Subsequences - Why Naive Fails

The trap

Generate all subsequences of s and count matches with t.

A string of length mm has 2m2^m subsequences. Checking each against t is O(n)O(n).

Total: O(n2m)O(n \cdot 2^m). Exponential in s's length.