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 Timely Orders problem solution

YASH PAL, 31 July 202415 February 2026
In this HackerEarth Timely Orders problem solution Today, you have been given a task like ones back end developers face on a daily basis. You need to help in dealing with large amount of requests received in a purchasing application. The application has the following properties:
  1. Consumers place large number of orders via this application
  2. Each request has a time stamp and an order size associated with it.
  3. Each order size is considered in terms of kilo-grams and can be of integer weight only.
Now, the data analytics team needs some information on regular intervals. Based on the requests received in the app, you need to help answer all queries posed by the data-analytics team. So, your task is:
 
Given 2 types of queries, the first one being of the form 1 X T, indicates an order of weight X is received at time T. The second one is of the form 2 K T indicates that the data analytics team asks you about the summation of weight of the orders received during the last K minutes at time T. The first query can be of the first type only.
 
For each query, it is guaranteed that they are given in ascending order of time. It means that given q queries and each query having a time T associated with it, Ti < Ti+1 < Ti+2 … < Tq.
 
 
 
HackerEarth Timely Orders problem solution

 

 

HackerEarth Timely Orders problem solution.

#include<bits/stdc++.h>

using namespace std;

int main(){

long long q;

cin>>q;

vector<pair<long long,long long>>ans;

while(q--){

long long a,b,c;

cin>>a>>b>>c;

if(a==1){

ans.push_back({c,b});

}else {

long long sum=0;

for(long long i=ans.size()-1;(ans[i].first>=(c-b))&&i>=0;i--){

sum+=ans[i].second;

}

cout<<sum<<"n";

}

}

}
 
 
 
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