Specification problem:
This is Christmas! You must buy gifts!
You have a set of existing toy packages and the corresponding price of the kit:
1 0 0 1 0 1 1 1 0 => 58 0 1 0 0 1 1 1 0 0 => 27 1 1 1 0 0 0 1 0 0 => 46 0 0 0 0 1 1 1 1 0 => 73 ...
Where a 1 indicates that the toy is in a bundle, and a 0 that it is not.
Now the Santa Claus promotion is coming up, and the rest of X offered to you at a special special price. We say that X is a bad deal if there is another bundle Y , so that:
Edit: to make this simpler, I reset condition 3, but changed condition 1 from “subset” to “strict subset”
X is a strict subset of YX more expensive than Y
The goal is to implement the bool isBadSubset(X) function, which effectively detects whether X good or not.
Given that there are millions of beams, comparing them with each of them is obviously impossible. Moreover, you can assume that in the existing bundle collection, a subset of toys is always cheaper than a superset.
Tips:
- comparing whether a set is a subset or not another set is easy
- you can limit the comparison to a set that contains at least
N more toys and cheaper. However, the list may be large. - something in the direction of the sieve will be fine
- you don’t need to know which package is better ... just the one that is better exists
Objective: is it possible to achieve this in a constant time? (regardless of the number of packages currently in the collection) ... or at least in log (n)?
source share