Impressing the Boss

  • + 0 comments
    static String canModify(int[] a) {
            /*
             * Write your code here.
             */
            int [] temp = a.clone();
            for(int i = 1; i<a.length; i++){
                if(a[i]<a[i-1]){
                    temp[i-1]=a[i];
                    a[i] = a[i-1];
                    break;
                }
            }
            int x = 0;
            int y = 0;
            for(int i = 0; i<a.length-1; i++){
                if(a[i]>a[i+1])
                    x++;
                if(temp[i]>temp[i+1])
                    y++;
                
            }
          return x==0 || y==0 ? "YES":"NO";
    
        }