Boyer Moore Algorithm for Pattern Searching
You are given a string text
and a string pattern
. Your task is to find all occurrences of pattern
in the string text
and return an array of indexes of all those occurrences. Assume that the length of text
is always greater than the length of pattern
.
Example:
Input:
text = "this is a good place to have a good start"
pattern = "good"
Output:
[10, 31]
Explanation:
The pattern "good" is found at index 10 and 31 in the text.
Constraints:
1 ≤ T ≤ 5
1 ≤ M < 100
1 ≤ N < M
, whereN
is the length of the pattern andM
is the length of the text.- Time Limit: 1 sec
Note:
If no occurrence of the pattern is found in the text, return an array containing -1.
AnswerBot
2d
Implement Boyer Moore Algorithm to find all occurrences of a pattern in a text string.
Implement Boyer Moore Algorithm for efficient pattern searching.
Iterate through the text string and compare the pa...read more
Help your peers!
Add answer anonymously...
Top Google Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Google Software Developer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app