Question: please explain thought process and use the define function given in picture Needle in haystack Given two strings needle and haystack, return the index of
please explain thought process and use the define function given in picture
Needle in haystack 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: 6 Explanation: "sad" occurs at index 0 and 6. The first occurrence is at index 0, so we return 0. Example 2: Input: haystack "leetcode", needle "Leeto" Output: -1 Explanation: "Leeto" did not occur in "Leetcode", so we return -1. + scaffold py 1 def solution (haystack, needle): 2 your code goes here nomerscaffold.py Spaces: 4 (Auto) All changes saved Terminal Mark Click here to activate the terminal
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
