Interview Questions and Answers for 'Yahoo' - 4 question(s) found - Order By Newest Very frequently asked across all types of companies. Q1. Difference between HashMap and Hashtable? Core Java
Ans. Hashtable is synchronized whereas HashMap is not.HashMap allows null values whereas Hashtable doesnt allow null values. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   collections   hashmap   map   hashtable   hashmap vs hashtable Asked in 14 Companies basic   frequent Try 2 Question(s) TestAdvanced level question frequently asked in US based companies. Recently asked in EMC and Intuit. Q2. Can you provide some implementation of a Dictionary having large number of words ? Solution
Ans. Simplest implementation we can have is a List wherein we can place ordered words and hence can perform Binary Search.
Other implementation with better search performance is to use HashMap with key as first character of the word and value as a LinkedList.
Further level up, we can have linked Hashmaps like ,
hashmap {
a ( key ) -> hashmap (key-aa , value (hashmap(key-aaa,value)
b ( key ) -> hashmap (key-ba , value (hashmap(key-baa,value)
....................................................................................
z( key ) -> hashmap (key-za , value (hashmap(key-zaa,value)
}
upto n levels ( where n is the average size of the word in dictionary. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java   collections   hashmap   binary search   search algorithm   advanced   architecture   data structure Asked in 6 Companies   frequent Try 1 Question(s) Test Q3. Write a Program to check if 2 strings are Anagrams ? Core Java
Ans. public void checkIfAnagram(String str1,String str2){
boolean anagram = true;
for(char c:str1.toCharArray()){
if(!str2.contains(String.valueOf(c))){
System.out.println("Strings are Anagrams");
anagram = false;
}
if(anagram == true){
System.out.println("Strings are not Anagrams");
}
}
} Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   check if 2 strings are Anagrams Asked in 30 Companies basic   frequent Q4. Explain the challenging problems you faced recently and how you overcame it ? General
Ans. [Open Ended Answer] Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  elsevier   open ended questions   overstock.com   cerner Asked in 15 Companies   frequent