Intermediate Level
Implement the letterCombinationsPhoneCount method that counts letter combinations generated from phone digits.
The input is a string digits containing phone keypad digits.
Each digit maps to a group of letters, like 2 -> abc, 3 -> def, and so on. Your task is to count how many letter combinations can be formed by choosing one letter for each digit.
For example, digits 23 can form 3 × 3 = 9 combinations. If the input is empty, return 0.
Use the size of each digit's letter group.
Every digit contributes a number of choices. For digits 2, 3, 4, 5, 6, and 8, there are 3 choices. For digits 7 and 9, there are 4 choices.
Multiply the choices for all digits to get the total number of combinations.
Pseudocode:
function letterCombinationsPhoneCount(digits):
if digits is empty:
return 0
map = {
'2': 3, '3': 3, '4': 3, '5': 3,
'6': 3, '7': 4, '8': 3, '9': 4
}
count = 1
for each digit in digits:
count = count * map[digit]
return count