Facebook Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
0
of 0 vote

For 1st part:
If one digit represents 3 letters. So, 4 digit will represent 3^4 combinations of strings. We can do that in a for loop ?

For 2nd part:
After getting output from 1st part, we can check if (combination present in dict. ) ?
and output accordingly. ?

- bebo October 20, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Just a heads up - on a telephone keypad, 0,1,*,# have no letters (easy workaround - assume these buttons have only one letter each - equal to the button face value) while 7 has 4!

- Anonymous November 02, 2010 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

public class Phone2Text {
	private static String[] mapping = { "ABC", "DEF", "GHI", "JKL", "MNO",
			"PQR", "STU", "VW", "XY", "Z*#" };

	public static void combinations(int[] number, char[] buf, int numIndex) {

		for (int i = 0; i < mapping[number[numIndex]].length(); i++) {
			buf[numIndex] = mapping[number[numIndex]].charAt(i);
			if (numIndex < number.length - 1) {
				combinations(number, buf, numIndex + 1);
			} else
				System.out.println(buf);
		}
	}

	public static void main(String[] args) {
		int num[] = { 5, 8, 5, 5, 0, 3, 3, 4, 4, 7 };
		Phone2Text.combinations(num, new char[num.length], 0);
	}
}

- Anonymous December 16, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

@anonymous can you please explain the algorithms

- angad May 28, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

#pay attention to the mapping.

- weijiang2009 February 06, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Build a trie by number instead of character

- Anonymous February 21, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

python:

n2l = { 1:"ABC", 2:"DF", 3:"GHI", 4:"JKL", 5:"MNO", 6:"PQR", 7:"STU"}
   
def gen(S,G=''):
    if not S:
        print G
        return
    else:
        for l in n2l[int(S[0])]:
            gen(S[1:], G+l)
gen("123")

- q July 13, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

<pre lang="" line="1" title="CodeMonkey23618" class="run-this">import Data.Array (listArray, (!))
import Data.Char (digitToInt)
import Data.Set (fromList, member)

keyMap = listArray (2, 9) ["ABC", "DEF", "GHI", "JKL", "MNO", "PQRS", "TUV", "WXYZ"]

digitCombinations digits = sequence $ [keyMap ! i | i <- digits]

dictionary = fromList ["DOG", "CAT", "BIRD", "REPTILE"]

main = do
numberString <- getLine
let numberCombinations = digitCombinations $ map digitToInt numberString
return $ filter ((flip member) dictionary) numberCombinations
</pre><pre title="CodeMonkey23618" input="yes">
</pre>

- Anonymous December 10, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

string lookup[10] = {"","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"};

int coi(char c){
	return ((int)c - 48);
}

void print(string oldString, string newString)
{
	if (oldString.length() == 0) {
		cout << newString << endl;
		return;
	}
	else {
		string characters = lookup[coi(oldString[0])];
		int numOfChars = characters.length();
		
		for(int i=0; i<numOfChars; ++i)
		{
			print(oldString.substr(1),newString+characters[i]);
		}
	}
}

- Anonymous July 16, 2012 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More