If your laptop was infected with viruses or malware, replacing or doing a full reformat of the hard drive will almost always get rid of it all (Provided you don't copy anything from that hard drive). However, if you have used and flash drives or external storage, there may be more hiding in those file systems as well. Best to run a full virus and malware scan on everything you may have plugged into that laptop since it got infected. I've never heard of a virus infecting RAM, since RAM is cleared after a shutdown. If the laptop had access to shared drives, files, or folders over your network, those public files may have gotten infected as well.
If you have an infection, try cleaning the system with antivirus and malwarebytes first before resorting to a format or hard drive replacement.