Search⌘ K
AI Features

Find the Index of the First Occurrence in a String

Find the Index of the First Occurrence in a String asks you to return the index where a target string first appears in a larger string, or negative one if it is absent.

Statement

Given two strings haystack and needle, return the index of the first occurrence of needle within haystack. If needle does not exist as a substring of haystack, return −1-1 ...