Amazon Interview Question: Given a 3x3 keypad with ABC o... | Glassdoor

Interview Question

Software Development Engineer Intern Interview(Student Candidate) Los Angeles, CA

Given a 3x3 keypad with ABC on number 2, DEF on number

  3 and so on. Given a set of numbers, output all the english words that can be obtained from it. Assume an in-built function exists to check if the given word is an english word or not. Eg: inuput: 228, output: bat, cat, act and so on.

Interview Answer

3 Answers


public static List wordCount(int input1, int input2, int input3){
List[] LL = new List[10]();
LL[1] = new List(a, b, c);...etc.
String temp = NULL;
List[0] = new List();
    for(char ch1 : LL[input1]){
        for(char ch2 : LL[input2]){
            for(char ch3 : LL[input3]{
                temp = "" + ch1 + ch2 + ch3;
    return LL[0];

I'm sure this has errors but it should do the trick and only took a few minutes to whip up.

Anonymous on Dec 14, 2015

phone_keybord = {

num = list(map(int,input()))

def gen_string(prefix, location, num, generated, phone_keybord):
    for i in range(len(phone_keybord[num[location]])):
        if(len(prefix)==len(num) and is_eng_word(''.join(prefix))):
            gen_string(prefix, location+1, num, generated, phone_keybord)

solution = []

gen_string([],0,num,solution, phone_keybord)

for i in range(len(solution)):

Anonymous on Jun 12, 2016

The problem is here if some one wants to practice.

Anonymous on Feb 14, 2017

Add Answers or Comments

To comment on this, Sign In or Sign Up.