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<Integerts=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

Popular posts from this blog

PROGRAM TO FIND FACTORIAL OF A NUMBER USING RECURSION

PROGRAM TO FIND THE COUNT OF PARTICULAR NUMBER IN AN ARRAY

TELEPHONE BOOK USING HASHMAP