data-structures · intermediate · ~15 min
Count keypad letter strings.
Implement:
long long count_letter_combinations(const char *digits);
On a phone keypad (2->3 letters, ..., 7 and 9 -> 4 letters), return the number of possible letter strings for a digit string. Digits 0 or 1, or an empty string, yield 0.
A digit string.
Number of letter strings.
Multiply the choices per digit.
#include <stddef.h>
/* Phone keypad: number of letter strings for a digit string (2->3 letters ... 9->4). Digits 0 or 1, or an empty string, yield 0. */
long long count_letter_combinations(const char *digits){ (void)digits; return 0; }
Assigning the wrong letter counts (7 and 9 have 4, not 3).
Empty or containing 0/1 -> 0.
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.