Coding Demons presents you the solution for a HackerRank problem "Angry Professor". The solution is given in two stages
Stage 1: Logic
Stage 2 : C++ Code
Logic :
- Take no of test case
- Repeat until all test cases are done
- Take no of students & threshold value
- Before time or on time present students have Negative no or zero
- Late students have positive no
- Count the no of negatives & zeroes (i.e. students on time)
- Compare with threshold
- If less print YES else NO.
Code :
/*** SOLUTION BY CODING DEMONS ***/
#include<bits/stdc++.h>
using namespace std;
int main()
{
int t,i;
cin>>t;
for(i=0;i<t;i++)
{
int n,k,j,x=0;
cin>>n>>k;
int a[n];
for(j=0;j<n;j++)
{
cin>>a[j];
if(a[j]<=0)
{
x++;
}
}
if(x>=k)
{
cout<<"NO\n";
}
else
{
cout<<"YES\n";
}
}
return 0;
}
/*** END ***/
0 Comments