text and fragment. Find the index at which fragment first appears in text as a contiguous piece and return it (0-based).
If fragment does not appear in text at all, return -1.
Try not to lean on built-in substring search: the search itself is the point of the exercise.text='bananas', fragment='ana' → 1
"ana" appears at positions 1 and 3 (the occurrences overlap). The first one is 1.
text='kettle', fragment='kettles' → -1
The fragment is longer than the text itself, so it cannot be found: the answer is −1.
text='abcabd', fragment='abd' → 3
text='bananas', fragment='ana'
1
Run checks the first 3 tests in your browser. Submit checks all 135 tests on the server, hidden ones included.