They are just looking for smart people. If you ever looked it up it's 5 lines of code. That's the whole point they're not forcing you to learn something:
A) so esoteric you will never encounter in your programming career B) so complicated that you'd have to spend days practicing it, etc
In my opinion a lot of these questions are disguised IQ tests wrapped in algorithms since they can't blatantly ask "brain teaser" questions anymore.