Program to perform Union operations
Program to perform Union operations
I/P:
5
3
1 2 3 4 5
7 8 3
O/p:
[1, 2, 3, 4, 5, 7, 8]
7
PROGRAM:
import java.util.*;
public class Union {
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int n1=sc.nextInt();
int n2=sc.nextInt();
TreeSet<Integer> ts=new TreeSet<>();
for(int i=0;i<n1;i++)
{
ts.add(sc.nextInt());
}
for(int i=0;i<n2;i++)
{
ts.add(sc.nextInt());
}
System.out.println(ts);
System.out.println(ts.size());
}
}
// 5
// 3
// 1 2 3 4 5
// 7 8 3
// [1, 2, 3, 4, 5, 7, 8]
// 7
Comments
Post a Comment