I am not an enthusiast of this approach to recruiting, but to be fair, the purpose of the question is not to find someone to flatten lists.
It is reasonable to ask, if a programmer cannot flatten a list, in what sense is that person a programmer? Putting aside the question of whether this is a good approach to recruiting, if this question is being failed with any regularity, it raises some interesting and important questions about the innate difficulty of programming and/or the methods by which it is taught.
It is the cases of failure that are interesting and informative, and if the methods you mention are the only ways a person can solve the problem, that counts as a failure - as I mentioned, this is not actually about flattening lists.
I mean, I once wrote a python script called unearthed.py that took all the files in all subfolders and put them into the parent folder, then deleted the subfolders, but I'm pretty sure I just used a simple os.walk for that.
Came in handy when working with rom archives that liked to put everything in its own folder, and a couple of times when I just had a bunch of crap that I didn't want to have to manually dig up anymore.
"Have you ever needed to flatten a list in your career outside exams and interviews?"
I had to write this function to flatten a tree of expressions, so I could sort them by precedence, etc and fold them into a tree. I already had a bunch of higher-order primitives for constructing a parser and that was basically a lazy hack for me to get expressions parsed. I eventually implemented a proper expression parser, that was basically the same thing, but produced a flat list from the beginning.
Flattening a list of lists is a problem that occurs quite frequently in functional programming.
OTOH, in functional programming languages and frameworks, there is no need to actually write a method that does that since it is usually a library function call.
We would send a request off to multiple services, wait for all the responses and then the front end would sometimes need all of the lists and other times need it flatten.
How would I do it?
var allitems = records.SelectMany(b => b).ToList();
Yes, multiple times in multiple languages. C, C++, Javascript... sometimes "npm install" is not the answer.