What should I do if I have previously seen a problem on a homework assignment?
This is not a difficult situation, you worked on a problem and understood the solution, then having it set as an assignment - your grade is based on the effort you have put in - either during the course or before.

Benefit from it - other topics you may not be so lucky...

Whether it is an assignment or a final exam - this is NOT cheating - you put the work in and that's fine.

If the professor was meant to write "new" questions and did not, instead re-using old ones then that is their problem, and they may not see it as a problem ie back to "it's the work you put in".

Some students will do every problem they can find on a topic, others will only do two and say "that's enough" - apart from the students with "genius" level or a photographic memory then the grades tend to follow effort...