Logo
IconChallenge
Icon
IconProblem
IconSolutions
IconSubmissions

Find the Index of the First Occurrence in a String

XPChallenge Points: 10
levelLevel: Easy

You are given two strings — text and pattern.
Your task is to find the index of the first occurrence of pattern inside text.
If the pattern is not found in text, return -1.
The search should be case-sensitive and based on the exact match of characters.

Example 1:

Input: text = "learningpython" pattern = "python"

Output: 8

Example 2:

Input: text = "developer" pattern = "code"

Output: -1

to Continue
like
dislike

Accepted:

Submission:

IconReport an issue
Icon
IconCode
IconYou need toto run or submitYou need toto run or submit
IconTest Case
IconTest Result