It's typical for companies to ask for coding samples or even have you write some simple programs to cover some concepts they are interested in (i.e. a take home test).
They could have been more courteous in case they weren't interested in proceeding with you.
However, I wouldn't worry about them using your stuff. If they aren't able to solve the problem you solved on their own, they have other problems to worry about.
Might be a good learning experience for you, better weigh the ROI of doing what a recruiter is asking you to do.