Microsoft Interview Question for SDE-2s


Country: India
Interview Type: In-Person




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

Text file can be too large to fit in RAM, so i will prefer .. Map-Reduce approach:

1. Split your text file in to small chunks to fit in RAM.
2. Check each word for palindrome within the node and update its frequency in HashTable. Than write table to secondary storage.
3. Collect result\table for each chunk and combine them all.
4. To combine the results we can use "external sort" kind of approach.

- Ajeet December 16, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Rather than using a HashMap. Use two. One that stores non palindrome values as HashMap<string,boolean> and the other one that stores the palindrome with its frequency.
HashMap<string, int>

- Rushabh October 19, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-2
of 2 vote

Create HashMap<String, Integer> where key is palindrome and value is the number of occurrences. Iterate over file and check if given word:

if(map.contains(word)) {
	map.put(word, map.get(word)+1);
} else if(isPalindrome(word)) {
	map.put(word,1);
}

You can also create a Set<String> 'noPalindromes' to avoid checking multiple times words which are not palindromes.

- thelineofcode December 15, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

A palindrome is bigger than a word.

- Anonymous December 16, 2013 | Flag
Comment hidden because of low score. Click to expand.
-2
of 2 votes

Good point. I'll update my response when I came up with a better idea

- thelineofcode December 16, 2013 | Flag


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