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, where N is the length of the pattern and M 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...
Google Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
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

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter