That happens for me as well, It's not about how do we achieve the results, it's all about how do you understand the algorithms, you may find a better solution in the future for the same problems so understand the logic, not the code.
And We are human beings we cannot remember everything that we learn every day.
Practicing and relating problems with others that you have already solved will help a lot.