Today it was a String day so, here it is today's problem:
Implement StrStr
Implement StrStr
From: InterviewBit
- Another question which belongs to the category of questions which are intentionally stated vaguely.
- The expectation is that you will ask for correct clarification or you will state your assumptions before you start coding.
- The expectation is that you will ask for correct clarification or you will state your assumptions before you start coding.
*Specifications are at the end of the entry. First, formulate your questions.
Ideas
* Assuming that A is length of haystack and B of needle, time complexity expected is O(N*M)
*If we are going to search in A, the first letter we need to find is B(0).
Solution:
https://github.com/AlexFaru/GoodCoding-/tree/master/String
Specifications :
Implement strStr().
strstr - locate a substring ( needle ) in a string ( haystack ).Try not to use standard library string functions for this question.
Returns the index of the first occurrence of needle in haystack, or
-1 if needle is not part of haystack.NOTE:
Good clarification questions:
For the purpose of this problem, assume that the return value should be -1 in both cases.
- What should be the return value if the needle is empty?
- What if both haystack and needle are empty?
