Ebay Interview Question
Software Engineer / DevelopersTeam: Traffic
Country: United States
Interview Type: In-Person
void Print(Vector<string>& elements, Lexicon& lex, string soFar) {
if (!lex.containsPrefix(soFar)) return;
if (lex.containsWord(soFar) && soFar.length() > 10) {
cout << soFar << endl; }
for (int i = 0; i < elements.size(); i++) { Print(elements, lex, soFar + elements[i]);
} }
void PrintAllWords(Vector<string>& elements, Lexicon& lex) {
Print(elements, lex, ""); }
Fixing some space issue.
void Print(Vector<string>& elements, Lexicon& lex, string soFar) {
if (!lex.containsPrefix(soFar)) return;
if (lex.containsWord(soFar) && soFar.length() > 10) {
cout << soFar << endl;
}
for (int i = 0; i < elements.size(); i++) {
Print(elements, lex, soFar + elements[i]);
}
}
void PrintAllWords(Vector<string>& elements, Lexicon& lex) {
Print(elements, lex, "");
}
Build a complete graph of all the symbols of the periodic table. Let the graph have n nodes in total. Do DFS for all of the n nodes in the graph and at each step check for the validity of the word traversed so far by looking up in the given dictionary.
- Murali Mohan January 08, 2014