Union of two arrays | 450DSA Solve with Python

admin
By -
0

 Union of two arrays



Problem: 

Given two arrays a[] and b[] of size n and m respectively. The task is to find the number of elements in the union between these two arrays.

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.


Problem Source: GeeksforGeeks


I have used simple  python arithmetical list join and applied  built-in len() function for getting total size of  final array list and for removing duplicate from joined list i have convert them in set and again set to list  so . because set only  can store unique data that's way, there is also available more simple and advanced tricks to solve this if you know then comments those into comment section below here please or if its helps you then share this .


Solution:

      class Solution:    

          #Function to return the count of number of elements in union of two arrays.

         def doUnion(self,a,n,b,m):

        

                 #code here

                 ab = a+b

                unique_list = list(set(ab))

        

               return len( unique_list)




#Join two python list 

#joined two arrays 

Post a Comment

0Comments

Put Your Thought or Query Here

Post a Comment (0)