ques 2

You are given n inputs and two numbers x and y. check whether all the given numbers lie in the range of x and y. (x <= y). If the condition is true print YES else print NO.

Example:

Input:  n = 5, x = 1,  y = 5,  a = [1,2,3,4,5]
Output: YES

Approach

C++

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n = 5x = 1y = 5;

    int a[n] = {12345};

    sort(aa + n);
    if (a[0] >= x && a[n - 1] <= y)
        cout << "YES\n";
    else
        cout << "NO\n";

    return 0;
}


No comments:

Post a Comment