Given two strings first and second, consider occurrences in some text of the form "first second third", where second comes immediately after first, and third comes immediately after second.

Return an array of all the words third for each occurrence of "first second third".

&nbsp;
Example 1:
Input: text = "alice is a good girl she is a good student", first = "a", second = "good"
Output: ["girl","student"]
Example 2:
Input: text = "we will we will rock you", first = "we", second = "will"
Output: ["we","rock"]

&nbsp;
Constraints:


	1 &lt;= text.length &lt;= 1000
	text consists of lowercase English letters and spaces.
	All the words in text a separated by a single space.
	1 &lt;= first.length, second.length &lt;= 10
	first and second consist of lowercase English letters.


class Solution:
    def findOcurrences(self, text: str, first: str, second: str) -> List[str]:
        pattern = r"(?<=\b" + first +" " + second + r" )[a-z]*"
        txt = re.findall(pattern,text)
        return txt
class Solution {
    public String[] findOcurrences(String text, String first, String second) {
        List<String> list = new ArrayList<>();
        
        String[] arr = text.split(" ");
        
        for(int i = 0; i < arr.length - 2; i++) {
            if(arr[i].equals(first) && arr[i + 1].equals(second)) {
                list.add(arr[i + 2]);
            }
        }
        
        String[] result = list.toArray(new String[0]);
        
        return result;
    }
}
class Solution {
public:
	vector<string> findOcurrences(string text, string first, string second) {
		vector<string>ans;
		int i=0;
		while(i<text.length())
		{
			string word = "";
			string secondWord="";
			while(i<text.length() && text[i]!=' ')
			{
				word = word+text[i];
				i++;
			}
			if(word == first)
			{
				int k = i+1;
				while(k<text.length() && text[k]!=' ')
				{
					secondWord = secondWord+text[k];
					k++;
				}  
				k++;
				if(k<text.length() && secondWord==second)
				{
					string tmp="";
					int j=k;
					while(j<text.length() && text[j]!=' ')
					{
						tmp = tmp+text[j];
						j++;
					} 

					ans.push_back(tmp);
				}
			}
		   i++;
		}
		return ans;
	}
};
var findOcurrences = function(text, first, second) {
    let result = [];
    let txt = text.split(' ');
    for(let i = 0; i<txt.length - 2; i++) {
        if(txt[i] === first && txt[i+1] === second) result.push(txt[i+2]);
    }
    return result;
};
Occurrences After Bigram