Code Room
CodingHardcod-g727
Subject Advanced dpLevel Senior–Staff~35 minCommon in Algorithms & data structures interviewsIndustries Software development

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.