LeetCode 763 Partition Labels - Why Naive Fails

The trap

Try all ways to partition and check if each letter stays in one part.

With length nn, there are 2n12^{n-1} ways to place partition boundaries. Checking each is expensive.

Can you find where each partition must end?