Print the count of number of elements in union and intersection separated by space.Constraints1 <= N, M <= 100
Question
Print the count of number of elements in union and intersection separated by space.
Constraints
1 <= N, M <= 100
Solution
Sure, here is a Python solution for your problem:
def count_elements(n, m, arr1, arr2):
# Convert the arrays into sets
set1 = set(arr1)
set2 = set(arr2)
# Calculate the union and intersection of the sets
union = set1.union(set2)
intersection = set1.intersection(set2)
# Print the count of elements in the union and intersection
print(len(union), len(intersection))
# Test the function
n = 5
m = 3
arr1 = [1, 2, 3, 4, 5]
arr2 = [4, 5, 6]
count_elements(n, m, arr1, arr2)
In this code, we first convert the input arrays into sets. Then we calculate the union and intersection of these sets using the built-in Python set methods union
and intersection
. Finally, we print the number of elements in the union and intersection by using the len
function.
Similar Questions
If m men and n women are to be seated in a row so that no two women sit together. If m>n, then the number of ways in which they can be seated is
If two sets are such that n (A intersection B) = ½ (AUB) = 6. Then a total number of elements in these sets is?A.9B.12C.16D.18
Write a python program to print the number of occurrences of a substring into a line
Find the number of times digit (1) is used while writing numbers from 1 to 100.
What will the following code print?counter = 1sum = 0while counter <= 6: counter = counter + 2 sum = sum + counterprint(sum)
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.