Back to problems

Distinct Products Of Prime Subsets

Algorithm · Snapchat · Medium

You are given an array primes consisting entirely of prime numbers. Some primes may appear more than once. Consider every possible non-empty subset of the array (i.e., any selection of one or more elements, regardless of order). For each such subset, compute the product of its elements. Your task is to return a list containing each distinct product that can be formed in this way. Implement the function compute_all_products(primes) that returns the list of unique products.…

Checking your access…