DescriptionQ619
Q619FWASIC interview problem
Find the first substring
TechniquesStringNested scan
DifficultyEasy
TopicStrings
LanguageSystemVerilog
Requirements3 checkpoints
01
Problem
Implement a function that returns the first index where sub appears inside s, or -1 when it is not present.
Example input and output
Use this case to check your interpretationInput
s = "silicon", sub = "lic"Output
2Explanation
The first matching window starts at index 2; the later characters are not scanned after that first match is found.
02
Requirements (3)
- Return 0 for an empty substring.
- Return -1 when the substring is longer than the input.
- Return the first matching index, not every match.
