I ask for code to candidates to be recruited but can actually gladly say it does not fall into the listed pitfalls here.
I consider this code to write like a discussion trigger.
I don't really care about the code make the unit tests pass. I'm more interested in the variables and methods being properly named, process made clear by reading code, responsibilities being properly isolated.
Candidates are free to use any code they can find anywhere if they can demonstrate they understand it during the interview.
The test is mutual, we test the candidate, the candidate test the company, we show her/him via the problem, what kind of problem the company aims to solve and how we intend to proceed, we check if the candidate can be complementary to the team, and the candidate can see if the team is a fit.
Test is short, we tell the candidate to take reasonable time for it and accept uncomplete solutions, then ask to explain during the interview how she/he would have completed it.