Code RoomSubset sum inversion
HardPrep Room Coding #4859

Subset sum inversion

CodingAlgorithms & data structuresSenior–Staff~32 min

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.

Implement
exact_flag_counts(cumulative: list[int]) → list[int]
Examples
in[[5,2]]out[3,2]
in[[10,6,7,4]]out[1,2,3,4]
in[[7]]out[7]
What a strong answer looks like

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.

0:00 of about 32 min
InputExpectedGot
[[5,2]][3,2]not run yetsample
[[10,6,7,4]][1,2,3,4]not run yetsample
[[7]][7]not run yetsample