First Occurrence In A String
Difficulty: Medium
Acceptance: %
Points: 30.00
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.
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: Amazon Walmart TCS Infosys Wipro
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.