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 = 5, x = 1, y = 5;int a[n] = {1, 2, 3, 4, 5};sort(a, a + n);if (a[0] >= x && a[n - 1] <= y)cout << "YES\n";elsecout << "NO\n";return 0;}
No comments:
Post a Comment