Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • IoT – Internet of Things
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone

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

Post navigation

Previous post
Next post
  • 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
  • Hackerrank Day 6 Lets Review 30 days of code solution
  • Hackerrank Day 14 scope 30 days of code solution
©2025 Programmingoneonone | WordPress Theme by SuperbThemes