1326. Check if a Set is a Subset of Another

MediumBit ManipulationBitmaskSubsetAND

Two sets are represented as bitmasks, where bit i indicates that element i belongs to the set. Given masks sub and sup, determine whether the set represented by sub is a subset of the set represented by sup.

Input: A JSON object {"sub": <bitmask>, "sup": <bitmask>}.

Output: Return true if every bit set in sub is also set in sup, otherwise false.

Examples

Example 1
Input: {"sub":5,"sup":7}
Output: true
Explanation: 101 is contained in 111 -> true.
Example 2
Input: {"sub":5,"sup":6}
Output: false
Explanation: 101 has bit 0 which 110 lacks -> false.

Constraints

Asked by

AmazonMicrosoftGoogleAdobeFlipkart
Solve this problem in the editor →