Interview Questions

There is a string S ans another string s1 .....

Software QA/Tests Interview Questions from Microsoft


(Continued from previous question...)

There is a string S ans another string s1 .....

Question:
a} There is a string S ans another string s1,
Design the algorithm to check if s1 is contained inside S and return the location as well.
Hint: Interviewer told me that this is a standard problem from book, {b} test cases to check this.


maybe an answer:


en.wikipedia.org/wiki/Rabin–Karp_string_search_algorithm
en.wikipedia.org/wiki/Knuth%E2%80%93Morris%E2%80%93Pratt_algorithm
en.wikipedia.org/wiki/Boyer%E2%80%93Moore_string_search_algorithm

Test cases:
null, null -> exception
null, not null -> exception
not null, null -> exception
empty, empty -> 0
not empty, empty -> -1
empty, not empty -> -1
S smaller than s1 -> -1
S larger than s1 with no occurrences of s1 -> -1
S larger than s1 with 1 occurrence of s1 -> index of s1
S larger, with multiple occurrences of s1 -> first index of s1

(Continued on next question...)

Other Interview Questions