Subset sum inversion
A telemetry service reports feature flag usage as a cumulative table and no longer keeps the raw sessions. Flags are numbered from 0, and every session is summarized by the mask of flags it had on, bit f standing for flag f. cumulative has 2^k entries for k flags: cumulative[m] counts every session whose mask has all the flags of m switched on, with any other flags allowed on top. cumulative[0] is therefore the total number of sessions. Return a list of the same length whose entry m is the number of sessions whose mask was exactly m. The table is always consistent with some real set of sessions, k is at most 12, and an empty table returns an empty list.
exact_flag_counts(cumulative: list[int]) → list[int][[5,2]]out[3,2][[10,6,7,4]]out[1,2,3,4][[7]]out[7]State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
[[5,2]][3,2]not run yetsample[[10,6,7,4]][1,2,3,4]not run yetsample[[7]][7]not run yetsample