Help me in solving ANADSW problem

My issue

How can you ensure that if N>=4 you can always have a sorted array,for example if you are given array as:1,3,2,4.How can you sort it based on condition given?

My code

#include <bits/stdc++.h>
using namespace std;
void solve(){
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }
    if(n>=4){
        cout<<"YES\n";
    }else{
        if(n==1) cout<<"YES\n";
        if(n==2){
            if(arr[0]<=arr[1]){
                cout<<"YES\n";
            }else{
                cout<<"NO\n";
            }
        }
        if(n==3){
            if(min(arr[0],arr[2])<=arr[1] and arr[1]<=max(arr[0],arr[2])){
                cout<<"YES\n";
            }else{
                cout<<"NO\n";
            }
        }
    }
}

int main() {
  int t;
  cin>>t;
  while(t--){
      solve();
  }
}

Problem Link: Anti Adjacent Swaps Practice Coding Problem - CodeChef

@top_coder111
plzz refer my c++ code

#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
        }
        if(n==1)
        cout<<"YES";
        else if(n==2)
        {
            if(a[0]<=a[1])
            {
                cout<<"YES";
            }
            else
            cout<<"NO";
        }
        else if(n==3)
        {
            int val=a[1];
            sort(a,a+3);
            if(a[1]==val)
            cout<<"YES";
            else
            cout<<"NO";
        }
        else
        cout<<"YES";
        cout<<endl;
    }
}