Is using an old book's solution considered cheating? I'm currently solving a coding problem. I remembered that i came across this problem in another book i studied myself to improve my coding in the summer.  That book has the same problem to this assignment. I understand the answer and know how to explain it but not sure if it is cheating to use that piece of code for my assignment.
One more thought in addition to Buffy's answer:

Transparency is maybe the solution here: tell your prof "I remember this problem, I met it studying book last summer. How shall I proceed with the assignment?"


This will ensure that there won't be any ground for accusing you of cheating
Prof may give you another assignment, from which you can learn more.