Google Interview Question Software Engineer / Developers




Comment hidden because of low score. Click to expand.
1
of 3 vote

What anonimous said its true to a certain point, but this problem is much easier that the pointed one. Can be done in O(n) time and O(n) space, given a dictionary of words.
Algorthm:
1. Split the input string in two parts between every characters.
2. check if both sides are present in dictionary, if so you have two words

public class SplitStrings {
	public static List<String[]> splitStr(Set<String> dictionary, String str) {
		List<String[]> options = new ArrayList<String[]>();
		for (int i=1; i<str.length();++i) {
			if (dictionary.contains(str.substring(0,i)) &&
				dictionary.contains(str.substring(i))) {
				options.add(new String[] {str.substring(0,i),
					str.substring(i)});
			}
		}
		return options;
	}
}

- lucas.eustaquio on August 03, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Use a Trie, backtracking may be needed.

- Softy on August 03, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

I actually gave the answer using trie. But it seems he was looking for an answer using hash (since memory is not a constraint).

- Newbie on August 03, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

same as : careercup.com/question?id=10060840

2 complete solutions (both based on DP) have been posted there.

- anonymous on August 03, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

these are not the same question. this question just asks how to find if there is a break between 2 valid words. other question asks how to insert spaces between multiple words.

- asdf11 on August 09, 2011 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Checkout the solution at avi-programming-blog.blogspot.com/2011/08/programming-challenge-ii-adding-spaces.html

- dongre.avinash on August 03, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I think the interviewer wanted to know if you can do something similar to Rabin-Karp algorithm. Basically keep building the first word by concatenating characters and compute hash (remember in R-K algo. the hash computation does not depend on the length of string). Similarly compute hash of the last word simultaneously (ok the first time it will be O(n-1) = O(n) but that's one time cost). If both hashes are present in dictionary only then do actual comparison, otherwise keep shifting a character from front of second word to the end of first word and repeat. Even if both words are present you must use other heuristics such as frequency of words and/or frequency of words occurring together to sort the list of words found as suggestions.

- Ashish Kaila on August 08, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Trie is more efficient than your algorithm.

- gavinashg on September 23, 2011 | Flag
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Use to prefix tree to get the sorted list of candidate breaking positions.
Use to suffix tree to get the sorted list of candidate breaking positions.
Find the common elements between two sorted lists.
Total time is O(N).

- bohu88 on December 08, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

-38!

bohu, you deserve an award.

- Anonymous on August 28, 2012 | Flag


Add a Comment
Name:

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

Books

is a comprehensive book walking you through every aspect of getting a job at a top tech company, while focuses on software engineering interviews.

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