HackerRank Tweets – HackerRank Solution

In this post, we will solve HackerRank Tweets HackerRank Solution. This problem (HackerRank Tweets) is a part of HackerRank Regex series.

Task

Increasing popularity of hackerrank can be seen in tweets like

  • I love #hackerrank
  • I just scored 27 points in the Picking Cards challenge on #HackerRank
  • I just signed up for summer cup @hackerrank

Given a set of most popular tweets, your task is to find out how many of those tweets has the string hackerrank in it.

Input Format

First line is an integer N. N lines follow. Each line is a valid tweet.

Constraints

  • 1 <= N <= 10
  • Each character of the tweet is a valid ASCII character.

Output Format

Print the total number of tweets that has hackerrank (case insensitive) in it

Sample Input

4
I love #hackerrank
I just scored 27 points in the Picking Cards challenge on #HackerRank
I just signed up for summer cup @hackerrank
interesting talk by hari, co-founder of hackerrank

Sample Output

4

Explanation

All the 4 lines have the string hackerrank in them and thus 4.

Solution – HackerRank Tweets – HackerRank Solution

Python

import re
p = re.compile('((h|H)(a|A)(c|C)(k|K)(e|E)(r|R)(r|R)(a|A)(n|N)(k|K))')
t = int(input())
c = 0
for i in range(t):
    x = str(input())
    c += len(re.findall(p, x))
print(c)

Note: This problem (HackerRank Tweets) 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 *