CodeCheffers are aware that after a contest, all problems are moved into the platform’s practice section. Based on user submissions during the contest, the system calculates and assigns a difficulty rating to each problem. Ideally, it is recommended that users practice problems in increasing order of difficulty.
Our Chef has some students in his coding class who are practising problems. Given the difficulty of the problems that the students have solved in order, help the Chef identify if they are solving them in non-decreasing order of difficulty. That is, the students should not solve a problem with difficulty d1d1, and then later a problem with difficulty d2d2, where d1>d2d1>d2.
Output “Yes” if the problems are attempted in non-decreasing order of difficulty rating and “No” if not.
Input Format
- The first line of input will contain a single integer TT, denoting the number of test cases. The description of the test cases follows.
- Each test case consists of 22 lines of input.
- The first line contains a single integer NN, the number of problems solved by the students
- The second line contains NN space-separated integers, the difficulty ratings of the problems attempted by the students in order.
Output Format
- For each test case, output in a new line “Yes” if the problems are attempted in non-decreasing order of difficulty rating and “No” if not. The output should be printed without the quotes.
Each letter of the output may be printed in either lowercase or uppercase. For example, the strings yes
, YeS
, and YES
will all be treated as equivalent.
Constraints
- 1≤T≤1001≤T≤100
- 2≤N≤1002≤N≤100
- 1≤1≤ difficulty of each problem ≤5000
//This code is written by Souvik Ghosh
import java.util.*;
public class difficultyRatingOrder {
public static void main(String[] args) {
//copy from here for code chef
Scanner sc = new Scanner(System.in);
int t=sc.nextInt();
for (int i = 0; i < t; i++) {
boolean isD=false;
int n=sc.nextInt();
int array[]=new int[n];
for (int j = 0; j < n; j++) {
array[j]=sc.nextInt();
}
for (int k = 0; k < n-1; k++) {
if(array[k]>array[k+1]){
isD=true;
break;
}
}
if(isD==true){
System.out.println("NO");
}else{
System.out.println("YES");
}
}
}
}