Find the Index of First Occurrence Problem

Find the Index of First Occurrence Problem — ExecCode School DSA Practice

Solve the Find the Index of First Occurrence problem on ExecCode. Free online school DSA practice in String. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Given two strings, haystack and needle, find the index of the first occurrence of needle in haystack. Your task is to solve Find the Index of First Occurrence. If needle is not part of haystack, return -1.

Examples

Input sadbutsad sad; Output 0. Input leetcode leeto; Output -1

Constraints

1 <= n <= 10^5

Practice Find the Index of First Occurrence free on ExecCode. Browse DSA problems, topic map, and placement guides.