Skip to content
Programmingoneonone
Programmingoneonone

LEARN EVERYTHING ABOUT PROGRAMMING

  • Home
  • CS Subjects
    • IoT ? Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone

LEARN EVERYTHING ABOUT PROGRAMMING

HackerEarth Timely Orders problem solution

YASH PAL, 31 July 2024
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

Post navigation

Previous post
Next post
  • Automating Image Format Conversion with Python: A Complete Guide
  • HackerRank Separate the Numbers solution
  • How AI Is Revolutionizing Personalized Learning in Schools
  • GTA 5 is the Game of the Year for 2024 and 2025
  • Hackerrank Day 5 loops 30 days of code solution
How to download udemy paid courses for free

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes