Math Fundamentals18 sections · 814 units
Open in Course

Letter Combinations - Counting First

(Product rule application)

Before generating combinations, you can count them using the product rule. For input "23": digit 2 has 3 letters, digit 3 has 3 letters. Product: 3×3=93 \times 3 = 9 combinations.

For input "234": 3×3×3=273 \times 3 \times 3 = 27 combinations. Each digit contributes independently.

This tells you the time complexity before you write any code. If the count is too large, you know generation will be expensive.