Save Patients

A new deadly virus has infected a large population of a planet. A brilliant scientist has discovered a new strain of the virus that can cure this disease. The vaccine produced from this virus has various strengths depending on midichlorians count. A person is cured only if midichlorians count in the vaccine batch is more than midichlorians count of the person. A doctor receives a new set of the report which contains midichlorians count of each infected patient, Practo stores all vaccine doctor has and their midichlorians count. You need to determine if the doctor can save all patients with the vaccines he has. The number of vaccines and patients is equal.

Example:

Input: n = 5, a[n] = {123, 146, 454, 542, 456}, b[n] = {100, 328, 248, 689, 200};
Output: No

Approach

C++

#include <bits/stdc++.h>
using namespace std;

void savePatients(int nint a[],
                  int b[])
{
    sort(a, a + n);
    sort(b, b + n);
    int flag = 0;
    for (int i = 0; i < n; i++)
    {
        if (b[i] < a[i])
        {
            flag = 1;
            break;
        }
    }
    if (flag)
        cout << "No\n";
    else
        cout << "Yes\n";
}
int main()
{
    int n = 5;

    int a[n] = {123146454542456};
    int b[n] = {100328248689200};

    savePatients(n, a, b);

    return 0;
}


Read Interview Questions

Exception Handling Interview Questions

DBMS Interview Questions Set -1

DBMS Interview Questions Set -2

SQL Interview Question Set -1

SQL Interview Question Set -2

JPA Interview Questions Set -1

JPA Interview Question Set -2

Hibernate Interview Questions

Spring Boot Interview Questions Set 1

Spring Boot Interview Questions Set 2


No comments:

Post a Comment