Impressing the Boss

  • + 0 comments

    CAN SOMEONE CORRECT IT import java.io.; import java.math.; import java.text.; import java.util.; import java.util.regex.*;

    public class Solution {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int t=sc.nextInt();
        while(t>0)
        {
            int n=sc.nextInt();
            int a[]=new int[n];
            for(int i=0;i<n;i++)
            {
                a[i]=sc.nextInt();
    
            }
            if(n==1)
            {
                System.out.println("YES");
            }
            else
            {
            int l=0,c=0;
            for(int i=0;i<n-1;i++)
            {
                if(a[i]>a[i+1])
                {
                    l++;
                }
                else
                {
                 c++;
                }
            }
            if(l==0||l==1)
            {
               System.out.println("YES");
            }
            if(l>1)
            {
                System.out.println("NO");
            }
            }
            t--;
        }
            }
    

    }