Microsoft Interview Question
SDE-2sCountry: India
Interview Type: In-Person
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.
Text file can be too large to fit in RAM, so i will prefer .. Map-Reduce approach:
- Ajeet December 16, 2013