One important thing to realize with paying people for code they write as applicants excludes a large number of potential hires. People on work visas are not allowed to moonlight. I wouldn't risk ending up on the wrong side of ICE just for an interview.
No they can't. If they did they would be doing volunteer work for a position that is usually paid and this also violates US immigration law (at least for the visas I'm aware of).