Check Subset in python HackerRank Solution

Hello Programmers, In this post, you will know how to solve the Check Subset in python HackerRank Solution. This problem is a part of the HackerRank Python Programming Series.

Ezoicreport this adCheck Subset in python HackerRank Solution
Check Subset in python HackerRank Solutions

One more thing to add, don’t directly look for the solutions, first try to solve the problems of Hackerrank by yourself. If you find any difficulty after trying several times, then you can look for solutions.

Check Subset in python HackerRank Solution

Ezoicreport this adproblem

You are given two sets, A and B.
Your job is to find whether set A is a subset of set B.
If set A is subset of set B, print True.
If set A is not a subset of set B, print False.

Input Format :

The first line will contain the number of test cases, T.
The first line of each test case contains the number of elements in set A.
The second line of each test case contains the space separated elements of set A.
The third line of each test case contains the number of elements in set B.
The fourth line of each test case contains the space separated elements of set B.

Constraints :

  • 0 < T < 21
  • 0 < Number of element in each set < 1001

Output Format :

Output True or False for each test case on separate lines.

Sample Input :

3
5
1 2 3 5 6
9
9 8 5 6 3 2 1 4 7
1
2
5
3 6 5 4 1
7
1 2 3 5 6 8 9
3
9 8 2

Sample Output :

True
False
False

Explanation :

Test Case 01 Explanation
Set A = {1 2 3 5 6}
Set B = {9 8 5 6 3 2 1 4 7}
All the elements of set A are elements of set B.
Hence, set A is a subset of set B.

Check Subset in python HackerRank Solutions

# Check Subset in python - Hacker Rank Solution
# Python 3
# Enter your code here. Read input from STDIN. Print output to STDOUT
# Check Subset in python - Hacker Rank Solution START
T = int(input())
for _ in range(T):
    a = input()
    A = set(input().split())
    b = int(input())
    B = set(input().split())
    print(A.issubset(B))
# Check Subset in python - Hacker Rank Solution END

Disclaimer: The above Problem (Check Subset in python) is generated by Hackerrank but the Solution is Provided by BrokenProgrammers. This tutorial is only for Educational and Learning purposes.

Next: Check Strict Superset in Python HackerRank Solution

Sharing Is Caring

Leave a Comment

Ezoicreport this ad