Skip to content
Programmingoneonone
Programmingoneonone

Learn everything about programming

  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • 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
Programmingoneonone

Learn everything about programming

HackerEarth Alex and Requests problem solution

YASH PAL, 31 July 2024
In this HackerEarth Alex and Requests problem solution, Alex is working in a firm, where he needs to process requests according to their priority. He has N allocation systems. At any instance, the ith system can process only one request with priority i or above.
For each request, on any eligible system, Alex can also terminate the request with less priority than that of the current request, in order to assign the current request to the system. There will be Q incoming requests and he needs to tell whether he can assign a system to each request or not.
Alex needs to assign each request to the system optimally, such that he can assign a maximum number of incoming requests. The number of requests (which are already assigned) terminated by Alex, doesn’t matter here.
HackerEarth Alex and Requests problem solution

HackerEarth Alex and Requests problem solution.

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
assert(n>=1 && n<=100);
int q;
cin>>q;
assert(q>=1 && q<=1e4);
int cur[105]={0};
while(q--)
{
int x;
cin>>x;
assert(x>=1 && x<=1e5);
int val=min(x,n);bool f=0;
for(int i=val;i>=1;i--)
{
if(cur[i]<x){cur[i]=x;cout<<"YESn";f=1;break;}
}
if(!f)cout<<"NOn";
}
return 0;
}
coding problems solutions

Post navigation

Previous post
Next post

Are you a student and stuck with your career or worried about real-time things, and don't know how to manage your learning phase? Which profession to choose? and how to learn new things according to your goal, and land a dream job. Then this might help to you.

Hi My name is YASH PAL, founder of this Blog and a Senior Software engineer with 5+ years of Industry experience. I personally helped 40+ students to make a clear goal in their professional lives. Just book a one-on-one personal call with me for 30 minutes for 300 Rupees. Ask all your doubts and questions related to your career to set a clear roadmap for your professional life.

Book session - https://wa.me/qr/JQ2LAS7AASE2M1

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

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