• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
September 21, 2023 |930 Views
SDE Sheet - Implement strstr
  Share   Like
Description
Discussion

This video is part of Strings section under GFG SDE Sheet.

In this video, Our task is to implement the function strstr. The function takes two strings as arguments (s,x) and  locates the occurrence of the string x in the string s. The function returns an integer denoting the first occurrence of the string x in s (0 based indexing).

Note: You are not allowed to use inbuilt function.

Example :

Input:
s = GeeksForGeeks, x = Fr
Output: -1

Explanation: Fr is not present in the string GeeksForGeeks as substring.

Try it out before watching the implementation of the problem in the video. We recommend watching the video, even if you can solve the problem. You may discover something new. All the best!!!

Do check out:-

Article: https://www.geeksforgeeks.org/check-string-substring-another/
Problem: https://practice.geeksforgeeks.org/problems/implement-strstr/1
SDE Sheet: https://www.geeksforgeeks.org/sde-sheet-a-complete-guide-for-sde-preparation/

Read More