I went through a similar experience with a radically different outcome. I was given a coding assignment and one week to finish it. I spent more than 30 hours on it and came up with a solution that was supposedly 500 times faster that what they'd ever seen (they told me this later). But things took a wrong turn at that point. In the followup meeting the interviewer turned out to be rude, disruptive, and combative. He tried to grill me on every little thing I said and finally rejected me. I have no idea how it happened but I suspect they simply thought my solution to the take-home assignment was too good to be mine.
Yes, I thought about both possibilities (discrimination and insecurity) but I want to remain positive and not attribute ulterior motives to the interviewer. It was an ironic experience though because, I believe, had my code been a bit slower I would have had a better shot at the interview.