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
4mo

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!
Select
Add answer anonymously...

Top Software Developer Interview Questions Asked at Google

Q. How would you design a Chrome update deployment strategy?
Q. What are your goals?
Q. What is Dijkstra's algorithm and how does it work?
Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits