Skip to content
Programmingoneonone
Programmingoneonone
  • Engineering Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
    • 100+ C++ Programs
  • Solutions
    • HackerRank
      • Algorithms Solutions
      • C solutions
      • C++ solutions
      • Java solutions
      • Python solutions
    • Leetcode Solutions
    • HackerEarth Solutions
  • Work with US
Programmingoneonone
Programmingoneonone

HackerEarth Roy and Trending Topics problem solution

YASH PAL, 31 July 202414 February 2026
In this HackerEarth Roy and Trending Topics problem solution, Roy is trying to develop a widget that shows Trending Topics (similar to Facebook) on the home page of HackerEarth Academy.
He has gathered a list of N Topics (their IDs) and their popularity score (say z-score) from the database. Now z-score change every day according to the following rules:
  1. When a topic is mentioned in a ‘Post’, its z-score is increased by 50.
  2. A ‘Like’ on such a Post, increases the z-score by 5.
  3. A ‘Comment’ increases the z-score by 10.
  4. A ‘Share’ causes an increment of 20.
Now the Trending Topics are decided according to the change in z-score. One with the highest increment comes on top and the list follows.
Roy seeks your help to write an algorithm to find the top 5 Trending Topics.
If a change in z-score for any two topics is the same, then rank them according to their ID (one with higher ID gets priority). It is guaranteed that IDs will be unique.
 
 
HackerEarth Roy and Trending Topics problem solution

 

 

HackerEarth Roy and Trending Topics problem solution.

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
using namespace std;
vector < pair<long long, long long> > topics;
map<long long,long long> id_zscore_map;
int main()
{
int n;
long long id, z, p, l, c, s;
scanf(" %d",&n);
for(int i=0;i<n;i++)
{
scanf(" %lld %lld %lld %lld %lld %lld",&id,&z,&p,&l,&c,&s);
topics.push_back(make_pair( (p*50 + l*5 + c*10 + s*20 - z) , id));
id_zscore_map[id] = z;
}
make_heap(topics.begin(), topics.end());
for(int i=0;i<5;i++)
{
printf("%lld %lldn",topics.front().second, id_zscore_map[topics.front().second] + topics.front().first);
pop_heap (topics.begin(),topics.end()); topics.pop_back();
}
return 0;
}
 
coding problems solutions HackerEarth HackerEarth

Post navigation

Previous post
Next post

Leave a Reply

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

Programmingoneonone

We at Programmingoneonone, also known as Programming101 is a learning hub of programming and other related stuff. We provide free learning tutorials/articles related to programming and other technical stuff to people who are eager to learn about it.

Pages

  • About US
  • Contact US
  • Privacy Policy

Practice

  • Java
  • C++
  • C

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes