If you haven't licensed your code to them, they shouldn't be able to legally incorporate it in their product. (Although perhaps you implicitly or explicitly gave them permission during the interview). But this is usually not very relevant as you probably will never know whether these companies are using your code or not.
If you only want to prevent companies from using your code in proprietary software, you could send them your code with a GPL license.
Copyright aside, yes, unpaid length projects during interviews are an atrocity.