Given two strings X and Y, the task is to find the last index in X at which string Y appears, if Y does not appear then the answer is -1.
Input: X = "geeksforgeeks", Y = "geeks" output: 9 Explanation: string "geeks" appears at index 1 and 9
Input: X = "geesforgees", Y = "geeks" output: -1 Explanation: "geeks" does not appear
You do not need to read any input or print anything. The task is to complete the function search(), which takes two strings as input and returns an integer.
Expected Time Complexity: O(|X| + |Y|)
Expected Auxiliary Space: O(|X| + |Y|)
1 ≤ |X|, |Y| ≤ 105
Both the strings contains lower case English alphabets
If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.