I just wish that in those cases the interviewee gives feedback and allows you to rewrite instead of just failing you. I mean in practice nobody writes library functions themselves unless absolutely necessary, but I get that for some positions you have to demonstrate that you can write lower-level code if you have to.
I think that it was probably a poorly designed question, but surely you could throw the interviewer a bone by giving a custom answer after they reject the library.
I love how your answer was straight, to the point and leverages existing standards, then scrolled up to the question and had to go through someone else's thorough, multipage response. Full marks to both answers!
[0] https://stackoverflow.com/a/1831841/61938