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.
Answer

Interview Answer

3 Answers

0

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;
                if(isEngWord(temp)){
                     LL[0].add(temp);
                 }
            }
        }
    }
    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
0

phone_keybord = {
        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'],
    }

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

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

solution = []

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

for i in range(len(solution)):
    print(solution[i])

Anonymous on Jun 12, 2016
0

The problem is here if some one wants to practice.
https://leetcode.com/problems/letter-combinations-of-a-phone-number/

Anonymous on Feb 14, 2017

Add Answers or Comments

To comment on this, Sign In or Sign Up.