You are given two strings, **text** and **pattern**. Determine the first index in **text** where **pattern** appears as an exact substring. - If pattern exists in text, return the starting index of its first occurrence. - If pattern does not exist in text, return **-1.**
Topics
Companies
Articles
Examples:
Expected Time Complexity: O(|text| * |pattern|)
Expected Space Complexity: O(1)
Constraints:
1 <= |text|,|pattern| <= 10^3
text and pattern consists of lowercase alphabets.
Companies:
AmazonWalmartTCSInfosysWipro
Topics:
String
Please log in to access the Submissions tab, where you can review your progress and explore code submissions from other participants.
Please log in to access the Solution tab and view detailed answers and explanations.
Please log in to access the Discussion tab and join conversations with other participants.
Access Restricted: Please Login to access the code editor and test cases.