Given strings haystack and needle, return the index of the first occurrence of needle in haystack, or -1 if not found.
Input: haystack = 'sadbutsad', needle = 'sad' Output: 0 Input: haystack = 'leetcode', needle = 'leeto' Output: -1
Unlock hints progressively β start gentle, go deeper only if needed.
Level 1: Gentle Nudge
A subtle direction
Level 2: Approach
The algorithm to use
Level 3: Detailed
Step-by-step guidance
to save progress and use AI features