Microsoft Interview Question

Write code to search a substring from another string

Interview Answers

Anonymous

Jun 9, 2010

look for all boundary conditions, substring larger than main string, etc

Anonymous

Jun 11, 2010

It goes fater to start comparing from the end of the searching string then from the begining; if the comparred chars do not match, move the search index directly to the possition of that char in the search string; this goes stright if chars do not repeat in the search string; otherwise you have to build a matching helper array somehow... This is a fastest method I know, and works faster for longer search strings.