Example :
S1 : abcde
S2: cdef
Answer : cde
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s reasonable to assume the set of characters is small and finite compared to the potential string length. So, handling 8-bit characters for example (in roughly-C++ pseudo-code):
Note that using a hash table rather than an array is a huge waste of time (unless handling say a 32-bit character representation).
An implementation of the simplification suggested in Yordan’s comment follows. This avoids the final loop from 0..255 and needs only one tracking array. The order of results is unsorted.