Here's the full solution:
plaintext function subsetSumExists(arr, target) n := length of arr for mask := 0 to (1 << n) - 1 sum := 0 for i := 0 to n - 1 if (mask >> i) & 1 = 1 then sum := sum + arr[i] if sum = target then return true return false
Time: . For each of masks, we check bits. Space: extra. This is your first complete bitmask solution. The pattern is simple: iterate masks, extract bits, compute answer.
Time complexity: .
Space complexity: .