I personally enjoy programming exercises and have no problem spending a few hours tackling these types of problems.
However I'd refuse to do it for free if it's obviously something they're going to use in their product or if it's something that takes 20 hours to complete.