Subset sum inversion

Write codeHard32 minGoogle style

Your task

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.

Examples

exact_flag_counts(cumulative: list[int]) -> list[int]
Example 1
Inputexact_flag_counts([5, 2])
Output[3, 2]
Example 2
Inputexact_flag_counts([10, 6, 7, 4])
Output[1, 2, 3, 4]
Example 3
Inputexact_flag_counts([7])
Output[7]