privacy – subset of resolution for two sets

Some bitcoin transactions (especially CoinJoin transactions) include two or more subtransactions. for example, consider a transaction with
Inputs = [2, 3, 4] and
Outputs = [4, 5].

In this example, we have two subtransactions:
(2 + 3 = 5) and (4 = 4)
it is thus a kind of problem of sum of subsets but for 2 sets, inputs and outputs.

I want to know how to resolve the subset sum for this specific problem. I know it requires brute force, but how to optimize it? I do not know how to use brute force either.