Can I buy a domain that used to have spam on it and still rank?

Can I buy a domain name on the secondary market that has a lot of spam on it and still rank? How can I reset the SEO of that domain ? Thousands of root domai…