Code RoomSubmask maximum
HardPrep Room Coding #1292

Submask maximum

CodingAlgorithms & data structuresSenior–Staff~35 min

Given n (number of bits) and an array val of length 2**n where val[m] is a weight assigned to subset m, for each mask m compute the maximum val[s] over all submasks s of m (s & m == s). Return the array of these per-mask submaximums. Constraints: 1 <= n <= 14. The SOS-style DP generalizes from sum to max in O(n * 2**n); naive submask enumeration is O(3**n) and too slow at the top.

Implement
max_over_submasks(n: int, val: list[int]) → list[int]
Examples
in[2,[4,1,7,2]]out[4,4,7,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 35 min
InputExpectedGot
[2,[4,1,7,2]][4,4,7,7]not run yetsample