Question: Problem statement: Given two strings text and pattern find the first occurrence of str1 in str2 if found print its index if not found print

Problem statement: Given two strings text and pattern find the first occurrence of str1 in str2 if found print its index if not found print -1.

Examples:

Example 1: Input: str1 = "takeuforward" str2 = forward Output: 5 Explanation: "Forward" is present in the 5th index in "takeuforward"

Example 2: Input: str1 = hello str2 = az Output: -1 Explanation: "az" is not a substring of "hello"

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related General Management Questions!