Leetcode Problem 1452. People Whose List of Favorite Companies Is Not a Subset of Another List

1452. People Whose List of Favorite Companies Is Not a Subset of Another List

Leetcode Solutions

Dictionary + Bitwise Operation

  1. Create a set of all unique companies across all favorite lists.
  2. Assign each company a unique bit position in a binary number using a dictionary.
  3. Convert each person's favorite list into a binary representation based on the dictionary.
  4. Iterate over each person's binary representation and compare it with others using bitwise AND.
  5. If the result of the AND operation is equal to the person's binary representation, it is a subset.
  6. Collect indices of persons whose lists are not subsets of any other list.
UML Thumbnail

Set Intersection and Comparison

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...