UK and US: Part 2 – HackerRank Solution

In this post, we will solve UK and US: Part 2 HackerRank Solution. This problem (UK and US: Part 2) is a part of HackerRank Regex series.

Solution – UK and US: Part 2 – HackerRank Solution

Python

import re
sent = []
n = int(input())
for i in range(n):
    x = str(input())
    sent.append(x)
t = int(input())
for i in range(t):
    x = str(input())
    y = x
    c = 0
    x = x.replace('our','or')
    p = re.compile('(?:\s|\A)'+'('+x+'|'+y+')'+'(?=\s|\Z)')
    for sen in sent:
        c += len(re.findall(p, sen))
    print(c)

Note: This problem (UK and US: Part 2) is generated by HackerRank but the solution is provided by CodingBroz. This tutorial is only for Educational and Learning purpose.

Leave a Comment

Your email address will not be published. Required fields are marked *