Day 27: Testing Hacker Rank Solution In C++

Problem:- day 27: testing java or day 27: testing c++ or day 27: testing c++ or hacker-rank-30-days-of-code/Day27.java or day 27: testing hacker rank solutions or day 27: testing hacker rank solutions in c++ or hacker rank day 27: testing solutions or hacker rank day 27: solutions or Hackerrank 30 Days of Code Challenges solutions or day 27: solutions in C.

Explanation:- A Discrete Mathematics professor has a class of n students. Frustrated with their lack of discipline, the professor decides to cancel class if fewer than k students are present when class starts. Given the arrival time of each student, determine if the class is canceled.

Input Format

The first line of input contains t, the number of lectures.

The information for each lecture spans two lines. The first line has two space-separated integers, n (the number of students in the class) and k (the cancelation threshold). The second line contains n space-separated integers describing the array of students' arrival times (A = a0, a1, a2, . . . ,a(n-1)). 

Note: Non-positive arrival times (a(i)<=0) indicate the student arrived early or on time; positive arrival times (a(i)>0) indicate the student arrived a(i) minutes late. If a student arrives exactly on time ( a(i) = 0), the student is considered to have entered before the class started.

Output Format

For each test case, print the word YES if the class is canceled or NO if it is not.


When properly solved, this 


4 3
-1 -3 4 2
4 2
0 -1 2 1

Produces this 



For the first test case, k = 3. The professor wants at least 3 students in attendance, but only 2 arrive on time (-3 and -1). Thus, the class is canceled.

For the second test case, k = 2. The professor wants at least 2 students in attendance, and 2 to arrive on time (0 and 1). Thus, the class is not canceled.

Now there is contradiction according to this problem my first solution should work but I don't know why HackerRank is not accepting my solution and I tried much time but didn't succeed after a time I decide to read discussion section then I found a solution so for submitting solution you need to submit solution 2 and remember one thing there are no test cases for this question so you have to put custom test cases. The custom test case is below.

Custom Test Cases.

5 3
-1 90 999 100 0
4 2
0 -1 2 1
3 3
-1 0 1
6 1
-1 0 1 -1 2 3
7 3
-1 0 1 2 3 4 5

Submit this solution:- Click Here


using namespace std;

int main()
    int T,i,n,k,count;
    int arr[200];
        for(i = 0; i < n; i++)
        for(i = 0; i < n; i++)

Solution 2 (Submit This Solution)

using namespace std;

int main()
    cout<<"5 3"<<endl; 
    cout<<"-1 90 999 100 0"<<endl;
    cout<<"4 2"<<endl; 
    cout<<"0 -1 2 1"<<endl;
    cout<<"3 3"<<endl; 
    cout<<"-1 0 1"<<endl;
    cout<<"6 1"<<endl; 
    cout<<"-1 0 1 -1 2 3"<<endl;
    cout<<"7 3"<<endl; 
    cout<<"-1 0 1 2 3 4 5"<<endl;   


Day 27 Hacker Rank Solutions

Day 27 Testing Solution In C++

You May Also See

1. Day 28: RegEx, Patterns, and Intro to Databases

2. Day 29: Bitwise AND

3. Day 0: Hello, World.

4. Day 1: Data Types

5. Day 2: Operators
Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me