-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhashsetoperations.py
More file actions
86 lines (47 loc) · 1.86 KB
/
hashsetoperations.py
File metadata and controls
86 lines (47 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# HashSet Operations
# Given two arrays of size N and M, insert them into two sets A and B.
# Implement the following operations in the same sequential order:
# Union of A and B: Find the union of A and B, print the elements of the resulting set in sorted order.
# Intersection of A and B: Find the intersection of A and B, print the elements of the resulting set in sorted order.
# Symmetric Difference of A and B: Find the symmetric difference of A and B, print the elements of the resulting set in sorted order.
# Check if A and B are disjoint sets: If yes, print true, otherwise, print false.
# Check if A is a subset of B: If yes, print true, otherwise, print false.
# Check if A is a superset of B: If yes, print true, otherwise, print false.
# Input Format
# The first line of input contains N, the size of array1. The second line of input contains N elements of array1.
# The third line of input contains M, the size of array2. The fourth line of input contains M elements of array2.
# Output Format
# For subset, superset, and disjoint operations print True or False. And for remaining all operations, if resulting set is not empty, print the sorted set separated by spaces, otherwise skip printing the set.
# Constraints
# 1 <= N, M <= 50
# 1 <= array1[i], array2[i] <= 100
# Example
# Input
# 4
# 9 6 8 7
# 3
# 9 9 6
# Output
# 6 7 8 9
# 6 9
# 7 8
# false
# false
# true
# Explanation
# Self Explanatory
n=int(input())
a1=list(map(int,input().split()))
m=int(input())
a2=list(map(int,input().split()))
s1=set(a1)
s2=set(a2)
union=s1|s2
print(" ".join(map(str,sorted(union)))if union else "")
inter=s1&s2
print(" ".join(map(str,sorted(inter))) if inter else "")
symdiff=s1^s2
print(" ".join(map(str,sorted(symdiff))) if symdiff else "")
print("true" if s1.isdisjoint(s2) else "false")
print("true" if s1<=s2 else "false")
print("true" if s1>=s2 else "false")