Problem:https://www.hackerrank.com/challenges/py-check-strict-superset/problem?isFullScreen=true
Code:
# Enter your code here. Read input from STDIN. Print output to STDOUT
#Naive
'''
setA = set(map(int, input().split()))
n = int(input())
result = set()
for _ in range(n):
setB = set(map(int, input().split()))
result.add(setA.issuperset(setB))
if False in result:
print(False)
else:
print(True)'''
#Better:
setA = set(map(int, input().split()))
n = int(input())
for _ in range(n):
setB = set(map(int, input().split()))
if not setA > setB: # strict superset check
print(False)
break
else:
print(True)
'''
This program checks if setA is a strict superset of all other sets provided
as input.
Step-by-step explanation:
1. Read the first line of input, convert it to a set of integers called setA.
This is the main set that will be compared against other sets.
2. Read an integer n, which represents how many other sets will be compared
with setA.
3. Loop n times, once for each comparison set:
- Read the next line of input, convert it to a set of integers called setB.
- Check if setA is a strict superset of setB using the ">" operator.
- A strict superset means:
a) All elements of setB are in setA.
b) setA has at least one element not in setB (so the sets are not equal).
- If setA is not a strict superset of setB, print False and stop immediately.
4. If the loop completes without finding any setB that fails the check,
print True. This means setA is a strict superset of all sets.
Note:
- The 'else' attached to the for-loop runs only if the loop was
not interrupted by a break.
- This allows the program to print True only if all checks pass.
'''