Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • 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

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

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