Array Limit | Competitive Programming Questions with Answers in Java
Competitive Programming Questions with Answers in Java
Array Limit
Problem
You are given n inputs and two numbers x and y. check whether all the given numbers lies in range of x and y. (x <= y). If the condition is true print YES else print NO.Input
First line contains N, X, Y separated by space.
Next Line contains n integers.
Sample Input
5 1 5
1 2 3 4 5
Sample Output
YES
Sample Output
YES
Solution
import java.util.*;
class TestClass {
public static void main(String args[] ) throws Exception {
int n, x, y, i;
Scanner s = new Scanner(System.in);
n = s.nextInt();
x = s.nextInt();
y = s.nextInt();
int[] a = new int[n];
for(i=0; i<n; i++)
{
a[i] = s.nextInt();
}
for(i=0; i<n; i++)
{
if(a[i] < x || a[i] > y)
{
System.out.println("NO");
System.exit(0);
}
}
System.out.println("YES");
}
}
Comments
Post a Comment