String Contains Substring Problem
String Contains Substring Problem — ExecCode School DSA Practice
Solve the String Contains Substring problem on ExecCode. Free online school DSA practice in Strings - Basics. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Given two strings, find the starting index of the first occurrence of the second string within the first string. Your task is to solve String Contains Substring. If the second string is not found, print -1.
Examples
Input hello world world; Output 6. Input the quick brown fox dog; Output -1
Constraints
1 <= len(S1),len(S2) <= 10^4
Practice String Contains Substring free on ExecCode. Browse DSA problems, topic map, and placement guides.