Coding problem
Letter strings for keypad digits
The task
A phone app suggests words while the user types on the number keypad. The keys hold these letters: 2 = abc, 3 = def, 4 = ghi, 5 = jkl, 6 = mno, 7 = pqrs, 8 = tuv and 9 = wxyz.
Complete PhoneWords(string digits). Return every string made by choosing one letter for each digit, in ascending ordinal order. An empty input gives an empty list. Throw ArgumentException for any character other than the digits 2 to 9. The input is never null.
Signature
public static List<string> PhoneWords(string digits)
Examples
"8"→["t", "u", "v"]. 8 has three letters."47"→["gp", "gq", "gr", "gs", "hp", "hq", "hr", "hs", "ip", "iq", "ir", "is"]. 3 letters times 4 letters, in alphabetical order.
Limits: Up to 8 digits.
The tests check: an empty input, one digit, two digits, keys with four letters, three and four digits, 0, 1 and other characters, and eight 9s (65,536 strings) in time.
Hints
Your code
Already included: using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net.Http; using System.Threading; using System.Threading.Tasks;
public static class Solution
{
// Every string made by choosing one letter for each digit, in ascending ordinal order.
public static List<string> PhoneWords(string digits)
{
throw new NotImplementedException();
}
}This problem comes with TechInterviewNotes Full Access
Unlock all paid content on TechInterviewNotes.