Help me with the logic of TWOCARD problem

My issue

can anyone explain me the approach of “two cards” problem

My code

import java.util.*;
import java.lang.*;
import java.io.*;

class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scan=new Scanner(System.in);
		int t=scan.nextInt();
		while(t-->0){
		    int n=scan.nextInt();
		    int A[]=new int[n];
		    int B[]=new int[n];
		    
		    for(int i=0;i<n;i++)A[i]=scan.nextInt();
		    for(int i=0;i<n;i++)B[i]=scan.nextInt();
		    
		    int maxA=Integer.MIN_VALUE;
		    int idx=-1;
		    for(int i=0;i<n;i++){
		        if(maxA<A[i]){
		              //System.out.println(maxA);
		            maxA=A[i];
		            idx=i;
		        }
		    
		        
		    }
		    int actualMax=-1;
		    int maxB=B[idx];
		  //  System.out.println(maxA+" "+maxB);
		    boolean flag=false;
		    for(int i=0;i<n;i++){
		        actualMax=Math.max(actualMax,B[i]);
		    }
		    
		    System.out.println(flag==true?"NO":"YES");
		}

	}
}

Problem Link: Two Cards Practice Coding Problem