Now, is the second type of code challenge (home work) better?
In my opinion, it is better, but it has it’s own issues.
Again, the main objection of the “home work” is to make it as comfortable as possible for the interviewer not the interviewee. You want them on your turf. You come up with some kind of an artificial problem. And you have your own opinions on how this problem should be solved. So a “good” candidate needs to strike the nerv. Solve it in a way that you approve.
This approach has some degree of “prove of cultural fitness” which is at-least something in comparison to the first approach.
However I believe the main problem is still the motivation behind the code challenge. The main motivation is to save time. I saw so many blunt and dumb code challenges, where you are bored out of your skull just by reading the assignment. Specifically if you have open source projects, which show you solve more complex problems. And than there is this second layer, which is much more important — the expectations of the interviewer. And those are mostly not expressed in the assignment. This results in a question:
How should I over-engineer this thing in order to be accepted?
This is a degree of paranoia, which should not be part of an interview process in my humble opinion.