2 ms·
> For example, you don’t need to actually keep every single page from Day 1 in the Map, just two, since the problem is “at least two pages” so a Set of size 2 o
by amluto 3y ago
> For example, you don’t need to actually keep every single page from Day 1 in the Map, just two, since the problem is “at least two pages” so a Set of size 2 or even an array of size 2 will use less memory than an unbounded Set.
That seems overcomplicated. For each customer on day 1, you either have multiple pages or you have a single page. If you see them on day 2 and they had multiple pages on day 1, then they are loyal. Or if they had a different page on day 1 than day 2, they’re loyal. (Or two different pages on day 2, but this comes along for free.)
So the data structure can be:
map<customerid, (MultiplePages | pageid)>
Where MultiplePages is choice in a sum type that doesn’t store any associated data. Or you can do:
map<customerid, optional<pageid>>
Where the none state of the optional means there are multiple pages, but this is a bit of an odd use of an optional.