eBay Interview Question: write code to do the reverse ... | Glassdoor

eBay

## Interview Question

Software Engineer Interview San Jose, CA

# write code to do the reverse mapping from phone number to

its all possible combination of letters. Ex- if dialed 12 then all possible combinations will be ad, ae, af, bd, be, bf, cd, ce, cf and so on...
Tags:
technical, analytical, algorithm

0

interviewer was not at all helpful, seems like she didn't know what I was talking about

Interview Candidate on Sep 2, 2012
1

This is a permutation problem. Each number maps to 3 or 4 letters, except zero, which does not map to anything.
Create map of each number to an array of characters: ncMap.get(1) returns {A,B,C}
Let int[] input be the phone number.

int print(int[] input, int inputStartPos, HashMap ncMap, List accumulator){
if(input == null || inputStartPos input.length-1) return -1;
Character[] chars = ncMap.get(input[inputStartPos]);
if(inputStartPos == input.length-1){
for(int i = 0; i < chars.length; i++){
printAccumulator(accumulator); // print all chars we have so far.
print(chars[i]);
}
return 0; // success
}
else {
for(int i = 0; i < chars.length; i++){
accumulator.append(chars[i]);
print(input, inputStartPos++, ncMap, accumulator);
}
}
}

Anonymous on Nov 12, 2012