Computer scienceProgramming languagesJavaInterview preparationAlgorithms and problem solving techniques

Understand the problem

Merge sort

Report a typo

You are given two integer arrays nums1 and nums2, sorted in non-decreasing order. Merge nums1 and nums2 into a single array sorted in non-decreasing order.

The first line of the input will be the nums1 array, and the second line of the input will be the nums2 array.

Sample Input 1:

1 2 4
2 5 6

Sample Output 1:

[1, 2, 2, 4, 5, 6]
Write a program in Java 17
import java.util.Arrays;
import java.util.Scanner;

class MergeSort{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int[] nums1 = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();
int[] nums2 = Arrays.stream(scanner.nextLine().split(" ")).mapToInt(Integer::parseInt).toArray();

//write your code here

}
}
___

Create a free account to access the full topic