Skip to content

Latest commit

 

History

History
68 lines (51 loc) · 1.27 KB

EXERCISE.md

File metadata and controls

68 lines (51 loc) · 1.27 KB

T9 Exercise

Map strings of digits to potential alphanumeric character strings using the T9 telephone keypad.

Background

Keypad

The keypad on most touch tone telephones and cell phones has a grid of digits (0-9). Most of the digits are also associated with a set of letters:

digit characters
0 0
1 1
2 A B C
3 D E F
4 G H I
5 J K L
6 M N O
7 P Q R S
8 T U V
9 W X Y Z

Mapping

An area code (e.g. 206) can be mapped through the T9 keypad:

2 0 6
A 0 M
B N
C O

to a set of alphanumeric strings:

A0M   A0N   A0O
B0M   B0N   B0O
C0M   C0N   C0O

Exercise

Basic

The basic exercise is to write an algorithm to print all possible mappings generated by a sequence of digits (e.g. 206) mapped via the T9 keypad. For example:

206 ->
  A0M
  A0N
  A0O
  B0M
  B0N
  B0O
  C0M
  C0N
  C0O

Extra Credit

Given an array of English words, how would you post-process the list of strings generated in the basic step looking for non-overlapping English words. Characters not in an English word would be reverted to digits. For example:

2069936413 -> b0myxdogle -> 20my9dog13