No, dynamic programming is when you split your bigger problem into a smaller one + 1 step to get to your bigger size. Then apply that recursively until you solve the trivial problem at the end and get back the answer for your original problem size.
No, that is plain old recursion. Dynamic programming is recursive programming with a twist. The twist is that identical sub-problems are short-circuited with memoization.
If you already have Sets handy - why not use the Set Intersection? (Assuming the Set implementation has that capability).
Re:Patterns.dev
by zelphirkalt on Thursday December 11, 2025 @12:42PM
(#46234518)
Putting both contents (lists, arrays, whatever you have) into sets, and then calculating the intersection might be more expensive than building the intersected set right away sourcing both non-set contents, I imagine. Though it would probably be easier to read and understand. But that can be solved by naming of functions that process the 2 non-set things.
Isn't this called 'dynamic programming'? It's actually a habit people should pick up when grinding leetcode.