I've done this for interviews - we showed them some code that had real bugs in it, as well as some poor design choices (we told them this in advance so they wouldn't think our real code was like that). We were looking for people who weren't afraid to tell us the code sucked and what they'd do to improve it. If they said it was fine as-is, or spotted very few of the bugs, that was a strong no-hire indication.
We tried sending the sample to them the day before, but there wasn't a strong correlation between doing that and good responses from the candidates. Basically, if they got it, they got it. And if they didn't, they didn't.