Domanda di colloquio di Amazon

Write a function which takes two strings as parameters and returns a string of common characters between the two strings but no duplicates. Use hash table to implement the algorithm.

Risposte di colloquio

Anonimo

12 mar 2012

(I chosed C# to do that)

Anonimo

14 mar 2012

Convert the strings into character arrays and then add the first string in Hashtable by looping through all characters of array and adding them in the Hashtable. Then in another loop check if characters of the second string are contained in Hastable. Complexity would be O(length of larger string).... I think it should work...

Anonimo

13 giu 2012

Actually you need to take care of the duplicates otherwise you will get duplicates. The following code provides correct answer. public class commoncharnodup { private static void noDup(String in1,String in2) { Hashtable inhash=new Hashtable(); StringBuilder commonChar=new StringBuilder(); for(int i=0;i