What was the thought process that led to this solution? Did day 24 remind you of some other problem you'd seen before?
Then I started to think about pruning the search space with early out. If you squint, there's a similarity here to bloom filters. It gives you two possible answers: definitely no, or possibly yes.
I was expecting to run in to issues where the state grew too large, but that turned out never to be the case.
An alternate way to approach it would have been with dynamic programming, but I didn't feel like that would be as much fun.