Pattern Searching
Easy Accuracy: 37.24% Submissions: 94 Points: 2

Given a text and a pattern, the task is to check if the pattern exists in the text or not.

Example 1:

Input: text = "geeksforgeeks"
       pat = "geek"
Output: 1
Explanation: "geek" exits in
"geeksforgeeks"

​Example 2:

Input: text = "geeksforgeeks"
pat = "gfg" 
Output: 0 
Explanation: "gfg" does not exits in 
"geeksforgeeks"

Your Task:  
You don't need to read input or print anything. Your task is to complete the function search() which takes the string two strings as inputs and returns 1 if the pattern is found, otherwise 0.

Expected Time Complexity: O(|text| + |pat|)
Expected Auxiliary Space: O(|text| + |pat|)

Constraints:
1 ≤ |text|, |pat| ≤ 105
Both the string contains lower case English alphabets

to report an issue on this page.

Editorial

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

Yes

All Submissions

My Submissions:

Login to access your submissions.