Question: import java.util. * ; class UnionOfTwoArraysBasicDSA { public static void main ( String [ ] args ) { Scanner sc = new Scanner ( System

import java.util.*;
class UnionOfTwoArraysBasicDSA{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
List A = new ArrayList<>();
List B = new ArrayList<>();
for (int i =0; i < n; i++){
A.add(sc.nextInt());
}
for (int i =0; i < m; i++){
B.add(sc.nextInt());
}
List result = unionOfTwoArrays(A, B);
for (int i : result){
System.out.print(i +"");
}
}
static List unionOfTwoArrays(List A, List B){
}
} Problem Description
You are given two arrays A and B of size n and m respectively. You need to find the resultant array of the union between these two arrays.
Elements are not necessarily distinct.
Note:-Union of the two arrays can be defined as the set containing distinct elements from both the arrays. If there are repetitions, then only one occurrence of element should be printed in the union.
Resultant Array should be in sorted order
Input format
Line 1: Two integers n and m denoting the size of the array A and B.
Line 2: An array of integers A separated by space.
Line 3: An array of integers B separated by space.
Output format
Return resultant list denoting the the union between these two arrays in sorted order.
Sample Input 1
53
12345
123
Sample Output 1
12345
Explanation
1,2,3,4 and 5 are the elements which comes in the union set of both arrays.
Sample Input 2
34
587
1785
Sample Output 2
1578
Explanation
1,5,7 and 8 are the elements which comes in the union set of both arrays.
Constraints
1<= n, m <=10^5
0<= A[i], B[i]<10^5 please provide code

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!