Header Ad

HackerRank Check Strict superset solution in python

In this Check strict superset, You are given a set A and n other sets. Your job is to find whether set A is a strict superset of each of the N sets. Print True, if A is a strict superset of each of the N sets. Otherwise, print False. A strict superset has at least one element that does not exist in its subset.

HackerRank Check Strict superset solution in python


Problem solution in Python 2 programming.

S=set([int(x) for x in raw_input().split()])
n=int(raw_input());stop=0
while n>0 and stop==0:
    n-=1
    B=set([int(x) for x in raw_input().split()])
    if not(S.issuperset(B) and len(S-B)>0): stop=1
if stop==1: print "False"
else: print "True"


Problem solution in Python 3 programming.

def isstrictsuperset(a,b):
    # true if a is a strict superset of b
    return b.issubset(a) and not(a.issubset(b))

a = set(int(x) for x in input().split(' '))
n = int(input())
res = True

for _ in range(n):
    b = set(int(x) for x in input().split(' '))
    res &= isstrictsuperset(a,b)
    
print(res)




Problem solution in pypy programming.

# Enter your code here. Read input from STDIN. Print output to STDOUT
A = set(raw_input().split())
is_strict_superset = True
for i in range(int(raw_input())): 
    B = set(raw_input().split())
    is_strict_superset = is_strict_superset and (A.intersection(B) == B and len(A) > len(B))
    
print is_strict_superset


Problem solution in pypy3 programming.

A = set(input().split())
N = int(input())
print(all(A > set(input().split())  for _ in range(N)))


Post a Comment

2 Comments

  1. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. a = set(map(int,input().split()))
      n = int(input())
      count = 0
      for _ in range(0,n):
      l = input().split()
      if len(l) == len(a.intersection(l)):
      count =+1
      if count == n:
      print(True)
      else:
      print(False)

      Sir, why is my code not working for testcase no. 2 and 4?

      Delete