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.Constraints1 <= 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
Given 2 arrays A and B of size N and M respectively. You have to find the number of elements in the union and intersection between both the arrays.Note that both the arrays contain distinct elements.Input FormatFirst line of input contains N - size of the array A. The next line contains the N integers of array A. The next line of input contains M - size of the array B. The next line contains the M integers of array B.Output FormatPrint the count of number of elements in union and intersection separated by space.Constraints
Max Ones in a RowMax Score: 20Given a M x N binary matrix, find the 0-indexed position of the row that contains the maximum count of ones, and the number of ones in that row. In case there are multiple rows that have the maximum count of ones, the row with the smallest row number should be selected.Input FormatThe first line of input contains integers M and N separated by space. For the next M lines, each line contains N elements separated by spaces.Output FormatPrint the index of the row, followed by the number of ones in it.Constraints1 ≤ M, N ≤ 100ExampleInput
Given an array of unique integer elements, print all the subsets of the given array in lexicographical order.Input FormatThe first line of input contains T - the number of test cases. It's followed by 2T lines, the first line contains N - the size of the array and the second line contains the elements of the array.Output FormatFor each test case, print the subsets of the given array in lexicographical order, separated by new line. Print an extra newline between output of different test cases.Constraints1 <= T <= 1001 <= N <= 100 <= A[i] <= 100ExampleInput335 15 3 257 96 43 15 8 23 Output3 3 5 3 5 15 3 15 5 5 15 15 57 57 96 96 3 3 8 3 8 15 3 8 15 23 3 8 23 3 15 3 15 23 3 23 8 8 15 8 15 23 8 23 15 15 23 23
Input FormatThe first and only line of input contains an integer N.Output FormatPrint the count of permutations.Constraints1 ≤ N ≤ 100ExampleInput8Output576
Print the sum of row 1 of A and row N of B, row 2 of A and row (N-1) of B and so on.Constraints1 <= N, M <= 100-102 <= mat[i][j] <= 102
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.