I have what seems like a simple problem, but I'm struggling to solve it. Turning to Google it appears this may be a variation of the Knapsack problem, but I'm having trouble mapping those solutions to this particular problem.
Let's say I have two lists of positive integers, A and B. I want to find the value that represents the largest common sum between these two lists.
A: [6, 1]
B: [5, 3, 1]
Here, the answer is 6, because that's the largest sum that can be created commonly in both lists (by removing the 1 in list A and removing the 3 in list B).
I can naively solve this in O(2^n) but I'm assuming there's a much more efficient approach via dynamic programming, though dp is not my strength.
Is this the knapsack problem? Any pointers as to how I should map the classic knapsack problem to this two-list problem?