⚡ Build the skills to land top-paying quant jobs. Offer ends in 17d 22h 18m 43s17 days 22 hours 18 minutes 43 seconds.
⚡ Build the skills to land top-paying quant jobs. Offer ends in 17d 22h 18m 43s17 days 22 hours 18 minutes 43 seconds.

Sign in to watch this lesson
Advanced - Number Theory · 4:39
The loop s = (s - 1) & m walks every submask of a bitmask m from the largest down, at two operations per step, because the allowed bits behave like a small counter being decremented. We handle the empty submask safely, prove that looping over all masks and all their submasks costs 3ⁿ rather than 4ⁿ, and use it for the classic dynamic program that splits a set into the best teams.