Leaving out that information from the question is going to disorient novices who in a high stress situation at the short end of an asymmetrical relationship. I suppose if the interviewer lets them Google, then it is a fair test (and objectively, not Googling before writing code is probably the best criterion for failing miserably).
What the question really measures is how lucky the candidate was in their education. If they were taught in Racket rather than Java:
(flatten '((1) ((2 3 ((4) (5 6)))))
and if they were taught the JVM rather than Java (flatten [[1] [[2 3 [[4] [5 6]]]]]
and with J flatten =: [: ; <S:0
I'd bet that the interviewer would not know if it was wrong or right. Which is the same issue of open endedness that the candidate faces.> What the question really measures is how lucky the candidate was in their education.
Yes! Exactly! This is the other point I wanted to make[1], thanks for doing it for me :)
> flatten =: [: ; <S:0
Nice, I was playing with J quite a lot but somehow missed the spread word (for the curious: http://code.jsoftware.com/wiki/Vocabulary/scapco)
[1] In my comment here: https://news.ycombinator.com/item?id=13725095
Well, I don't Java much, but I think that even if the result List is just integers, the source list has to be (invalid syntax) List<Integer | List<Integer>>, which is somewhat problematic to type as anything but List<Object> given Java's lack of sum types.
Note that in the genuine sum-type case you're wrapping, too.
If I were responsible for hiring developers into a Python post, I would only consider candidates to could show (ideally substantial) work in some other, strongly-typed, lower-level language. It hardly even matters if they haven't seen Python, a decent developer can become a useful Python programmer in a few hours. Python experience does not teach or demonstrate a decent understanding of software structure.
Whatever else you say about it, Java is one of the entry-level languages. It's no wonder there are many entry-level programmers among its users. It's obviously a trade-off, as you get that many more candidates to choose from, compared to for example OCaml, Clojure or Erlang programmers. On the other hand, a percentage of people who can flatten a list is greater in users of the more "advanced" languages.
If you want to have a good signal to noise ratio: avoid languages used in "Programming 101" like a plague and languages which are currently fashionable. This way you'll get candidates who learned the language by themselves, in most cases after learning and mastering their previous language.
Becoming a programmer is a long process. Depending on the person, the time required to learn a single programming language may be shorter than the time needed to really master all the essential programming skills. Which I think explains why there is a correlation between good programmers and people who know more than one programming language.