LeetCode 76 Minimum Window Substring - Why Naive Fails

The trap

Try all substrings of s. For each, check if it contains all characters of t.

There are O(n2)O(n^2) substrings. Checking each against t takes O(m)O(m) comparisons. Total: O(n2m)O(n^2 \cdot m).

For n=m=105n = m = 10^5, that's 101510^{15} operations. Far too slow.