It has to be a throw-away scenario and a throw-away code. Anything else is wildly unethical.
On the other hand the interviewing company should avoid such situations too because of the information secrecy - unless they are mandating an NDA with each and every candidate.