Sir my code is correct but it is too big so can u make this shorter

import java.util.Scanner;

class Patterntry {
static Scanner scn = new Scanner(System.in);

public static void main(String args[]) {
	int n = scn.nextInt();
	int[] arr1 = new int[n];
	insert(arr1);
	int[] arr2 = new int[n];
	insert(arr2);
	int[] arr = new int[2 * n];
	for (int j = 0; j < arr.length;) {
		for (int i = 0; i < arr1.length; i++) {
			arr[j]=arr1[i];
			j++;
		}
		for (int i = 0; i < arr2.length; i++) {
			arr[j]=arr2[i];
			j++;
		}
	}bublesort(arr);
	System.out.println(arr[(arr.length-1)/2]);
}

public static void insert(int[] arr) {
	for (int i = 0; i < arr.length; i++) {
		arr[i] = scn.nextInt();
	}
}

public static void bublesort(int[] arr) {
	for (int c = 0; c < arr.length - 1; c++) {
		for (int i = 0; i < arr.length - 1 - c; i++) {
			if (arr[i] > arr[i + 1]) {
				int temp = arr[i];
				arr[i] = arr[i + 1];
				arr[i + 1] = temp;
			}
		}
	}
}

}

@Harsh_Sonwani,
You are currently using a brute force approach which has a high time complexity but its correct.

Here is an alternate approach:

  1. Calculate the medians m1 and m2 of the input arrays ar1[] and ar2[] respectively.

  2. If m1 and m2 both are equal then we are done. return m1 (or m2) .

  3. If m1 is greater than m2, then median is present in one of the below two subarrays.
    a) From first element of ar1 to m1 (ar1[0…| n/2 |]) .
    b) From m2 to last element of ar2 (ar2[| n/2 |…n-1]) .

  4. If m2 is greater than m1, then median is present in one
    of the below two subarrays.
    a) From m1 to last element of ar1 (ar1[| n/2 |…n-1]) .
    b) From first element of ar2 to m2 (ar2[0…| n/2 |])

  5. Repeat the above process until size of both the subarrays becomes 2.

  6. If size of the two arrays is 2 then use below formula to get the median.
    Median = (max(ar1[0], ar2[0]) + min(ar1[1], ar2[1]))/2

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.