Timer is Running

Find Substring from last of the Given String
Submissions: 8   Accuracy:


  Difficulty: Basic   Marks: 1

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.

Example 1:

Input: X = "geeksforgeeks", Y = "geeks"
output: 9
Explanation: string "geeks" appears at 
index 1 and 9

Example 2:

Input: X = "geesforgees", Y = "geeks" 
output: -1 
Explanation: "geeks" does not appear

Your task:
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

** For More Input/Output Examples Use 'Expected Output' option **

Contributor: Saksham Raj Seth
Author: saksham seth

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.

Need help with your code? Please use ide.geeksforgeeks.org, generate link and share the link here.

to report an issue on this page.