unknown Interview Question
Software Engineer / Developerstemp = String A;
foreach elem in String B {
if(elem is present in temp) {
delete elem from temp;
}
}
print temp;
you can insert all the characters in string B into a hash table, than check every character in string A. It takes linear time.
If you are not conformable with hashing, you can sort A and B respectively and than identify the characters in A but not in B by a scan in a similar way as merge sort.
- Frodo Baggins August 21, 2010