Geeksforgeeks

Error

×

Leaderboard

Showing:

Handle | Score |
---|---|

@Ibrahim Nash | 5725 |

@blackshadows | 5685 |

@akhayrutdinov | 5111 |

@mb1973 | 4989 |

@Quandray | 4908 |

@saiujwal13083 | 4156 |

@sanjay05 | 3762 |

@marius_valentin_dragoi | 3511 |

@sushant_a | 3453 |

@KshamaGupta | 3318 |

@the_coder95 | 3302 |

Complete Leaderboard | |

Handle | Score |

@avaiesshaik782 | 786 |

@arpitsatnalika | 777 |

@tujhekya | 602 |

@prakharxyz | 601 |

@code_it_ | 591 |

@iamronak | 505 |

@imnm | 500 |

@pradeepkumarjad | 488 |

@satyam0460 | 481 |

@nitesha125 | 468 |

@Rahul Jadhav 1 | 466 |

Complete Leaderboard |

Your 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 and integer denoting the **first occurrence **of the string x in s (0 based indexing).

**Example 1:**

**Input:
**s = GeeksForGeeks, x = Fr
**Output: **-1**
Explanation: **Fr is not present in the
string GeeksForGeeks as substring.**
**

**Example 2:**

**Input:
**s = GeeksForGeeks, x = For
**Output: **5**
Explanation: **For is present as substring
in GeeksForGeeks from index 5 (0 based
indexing).

**Your Task:**

You don't have to take any input. Just complete the **strstr() **function which takes two strings **str, target** as an input parameter. The function returns -1 if no match if found else it returns an integer denoting the first occurrence of the x in the string s.

**Expected Time Complexity:** O(|s|*|x|)

**Expected Auxiliary Space:** O(1)

**Note **: Try to solve the question in constant space complexity.

**Constraints:**

1 <= |s|,|x| <= 1000

Login to report an issue on this page.

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

Yes
Implement strstr

...

Please choose 'ReadOnlyMode' if you needn't to 'Edit' the problem e.g. viewing OJ's solution, TestCase Files (TCFs), TimeLimit etc.