Let text = “this is a good place to have a good start”, pattern = “good” so you have to return {10, 31} because at 10 and 31 index pattern is present in the text.
If there is no such index in the text then just return an array containing -1.
The first line of input contains an integer ‘T’ denoting the number of test cases.
The first line of each test case contains a string ‘text’ in which the pattern will be searched for.
The second line of each test case contains a string ‘pattern’ of which you have to find all occurrences in ’text’.
For each test case, return an array representing the indices where the pattern is found in the text. The output of each test case is printed in a separate line.
You don’t have to print anything; it has already been taken care of. Just implement the given function.
1 <= T <= 5
1 <= M < 100
1 <= N < M
Time Limit: 1 sec
The idea is to find out which character mismatches in the text from the pattern that is the character of the text that doesn't match with the current character of the pattern and we call that character a bad character.
The idea is to shift the pattern to the right by the least amount that guarantees not to skip any occurrence of the good-suffix already matched. Good suffix heuristic is based on the matched suffix. Here, we shift the pattern to the right in such a way that the matched suffix subpattern is aligned with another occurrence of the same suffix in the pattern. The good suffix is the suffix that we have matched so far. We will have three cases here as discussed-
Ninja and Numbers
Longest Palindromic Substring
Cakes
1-3 Palindrome
Search Pattern (KMP - Algorithm)
Search Pattern (KMP - Algorithm)
Search Pattern (KMP - Algorithm)