Hardware interview practice
Find the first substring
Implement a function that returns the first index where sub appears inside s, or -1 when it is not present.
Reviewed example
Work through one case
Input
s = "silicon", sub = "lic"Expected output
2The first matching window starts at index 2; the later characters are not scanned after that first match is found.
What to cover
Requirements
- Return 0 for an empty substring.
- Return -1 when the substring is longer than the input.
- Return the first matching index, not every match.
