Given two strings needle and haystack, return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
Example 1
Input: haystack = sadbutsad, needle = sad
Output: 0
Explanation: "sad" occurs at index 0 and again at index 6. The first occurrence is at index 0, so we return 0.
Example 2
Input: haystack = algorithm, needle = algox
Output: -1
Explanation: "algox" matches the first four letters of "algorithm", but the fifth letter is 'r', not 'x'. It appears nowhere else, so the answer is -1.
Example 3
Input: haystack = hello, needle = ll
Output: 2
Explanation: "ll" starts at index 2 of "hello" (h=0, e=1, l=2).
Try every start position in the haystack where the needle could still fit, and compare the window of that length against the needle. Return the first position that matches.
Run checks all cases above. Submit evaluates all test cases.