• + 1 comment

    You're right! I've optimized my solution and removed the sorting, nice! Now min always holds the the highest value in a, and max holds the lowest in b.

    	int min = 0;
        	int max = Integer.MAX_VALUE;
    	for (int a_i = 0; a_i < n; a_i++) {
                int x = in.nextInt();
    			if(x > min) min = x;
                a[a_i] = x;
                
    		}
    		int[] b = new int[m];
    		for (int b_i = 0; b_i < m; b_i++) {
                int x = in.nextInt();
    			if(x < max) max = x;
                b[b_i] = x;
    		}