The reason that 31 is not a good answer in terms of securing a job is because your decisionmaker prides himself on being intelligent and he does not see arithmetic sequences as being sufficiently impressive. The reason pi is not a good answer is, despite there being uncountably many mathematical phenomena for which {1, 11, 21, pi} are correct answers, it is insufficiently elegant/tricky for what he has in mind.
A rigorous program expressing the sequences to which "pi" and "zebra" are the next answers takes only 0 bits and 1 bits respectively to compress in Patio11, a pedantic language created purely for the purpose of this post. It is far more rigorous than either English or C-style pseudocode, has a well-defined grammar, and could have an interpreter written in any common programming language that would fit on the side of a business card.
I stick with the original contention: any problem of this nature is about either identifying birds of a feather or lording one's intellectual superiority over the candidate.
"a(i)=i*10+1."
yours would be "a(3)=pi, a(4)=zebra, a(5)=cheetah, a(6)=akrcqfztaf a(7)=666" etc.
But I agree, if the question is just "what is the next element?" and so far only 3 are given, your answer is as good as anything else.
Ironically, the "problem" at hand appears to have come straight from that tutorial:
http://www.purplemath.com/modules/nextnumb7.htm
> Find the next number in the following sequence: 1, 11, 21, 1211, 111221,....
> This looks like a "math" sequence, but it isn't really. Instead, each term is a description of the preceding term. The first term is just one "1": 11. The second term is two "1's": 21. And so forth:
one 1: 11
two 1's: 21
one 2 and one 1: 1211
one 1, one 2, and two 1's: 111221
three 1's, two 2's, and one 1: 312211
So the next term is "312211".http://www.nathanieljohnston.com/2010/10/a-derivation-of-con...
And seeing this question is a sign that the interviewer is trying to feel smarter than you.
On a Cartesian grid is drawn a solid logo (e.g., show a picture of the Batman logo from the 1989 film), where each square represents a black or white pixel. How would you represent the image if you had to type the data points by hand for the computer to draw?
Both questions elude to run-length encoding.
What is the next line in the following sequence: 1 11 21 Answer: it's 1211 and the next is 111221
Why would 31 and 41 be illogical answers? I understand where 1211 comes from, but 31 and 41 are totally logical IMO. It's a linear function that goes up by 10.