Go•occurrences-after-bigram/solution.go
package main
import "strings"
func findOcurrences(text string, first string, second string) []string {
words := strings.Fields(text)
result := []string{}
for index := 2; index < len(words); index++ {
if words[index-2] == first && words[index-1] == second {
result = append(result, words[index])
}
}
return result
}
Python•occurrences-after-bigram/solution.py
class Solution:
def findOcurrences(self, text: str, first: str, second: str) -> list[str]:
words = text.split()
return [words[index] for index in range(class="syntax-number">2, len(words)) if words[index - class="syntax-number">2] == first and words[index - class="syntax-number">1] == second]
TypeScript•occurrences-after-bigram/solution.ts
function findOcurrences(text: string, first: string, second: string): string[] {
const words = text.split(class="syntax-string">" "); const result: string[] = [];
for (let index = class="syntax-number">2; index < words.length; index += class="syntax-number">1) if (words[index - class="syntax-number">2] === first && words[index - class="syntax-number">1] === second) result.push(words[index]);
return result;
}