We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home
  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Artificial Intelligence
  3. Natural Language Processing
  4. The Trigram

The Trigram

Problem
Submissions
Leaderboard
Discussions
Editorial

Given a large chunk of text, identify the most frequently occurring trigram in it. If there are multiple trigrams with the same frequency, then print the one which occurred first.

Assume that trigrams are groups of three consecutive words in the same sentence which are separated by nothing but a single space and are case insensitive. The size of the input will be less than 10 kilobytes.

Input: I love games. I love to code.
Here "games I love" is not a trigram because all the three words in trigram should be from the 
same sentence.

Input Format

A large chunk of text.

Constraints

The input contains lowercase or uppercase alphabets, whitespaces and dots.

Output Format

The most popular trigram - three words, with nothing but a space in between them. The output should be in lowercase. (If a trigram ends with dot then you should remove the dot.)

Sample Input 0

I came from the moon. He went to the other room. She went to the drawing room. 

Sample Output 0

went to the

Explanation 0

Here, "went to the" is the only trigram that has occurred maximum number of times.

Sample Input 1

I love to dance. I like to dance I. like to play chess.

Sample Output 1

i love to

Explanation 1

Here, Trigram "i love to" has occurred 1 time, "i like to" has also occurred 1 time. But since "i love to" occurred first, it will be the answer.

Author

PRASHANTB1984

Difficulty

Easy

Max Score

10

Submitted By

3236

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Helpdesk
  • Careers
  • Terms Of Service
  • Privacy Policy

Cookie support is required to access HackerRank

Seems like cookies are disabled on this browser, please enable them to open this website