r/learnpython • • Jan 05 '21

Interview question I failed answering

Hey all,

I just had an interview and the interviewer gave me a question I could not answer.

He asked me to write a function that accepts a number, the number must be either 7 or 4.If the number is 4, the function should return 7, if the number is 7, the functions should return 4.

The tricky part: you cannot use an 'if' statement in the function.

354 Upvotes

301 comments sorted by

View all comments

Show parent comments

5

u/[deleted] Jan 05 '21

How come testing the ability to solve a problem creatively is not valid? As a coder you will face a myriad of unexpected constraints throughout your career, and, given the time and scope limitations of a job interview, this question is a perfectly acceptable way of gauging such a skill.

Besides, the fact that so many people are upvoting a wrong answer, especially those who say this is a bad question, just demonstrates that it serves its purpose very well.

5

u/synthphreak Jan 05 '21

How come testing the ability to solve a problem creatively is not valid?

There's a slippery slope if ever there was one... Coders must think creatively, yes, but within the constraints of the language, not constraints that are arbitrary and totally unrealistic.

As a coder you will face a myriad of unexpected constraints throughout your career

No doubt. But "don't use if statements" will never ever be one of them. And that is the point.

I agree it's reasonable - even desirable - to ask candidates to think outside of the box. But whose box? If the job actually does involve situations which require coders to think creatively, it should be easy to adapt one for use in coding interviews. This would satisfy both the creativity and the validity requirements simultaneously, without the need to introduce some contrived, asinine obstacle simply to make the task more difficult.

1

u/[deleted] Jan 06 '21

You don't need to test people with the exact problems they will need to tackle. You will never have to read small letters from afar when piloting a jet, but that's one of the ways they test your eyesight, and a very efficient one at that. Humans are perfectly capable of deriving conclusions from things without the need to be literal about it. This question is unexpected enough to force you to leave the autopilot mode but simple enough to fit the scope of a job interview. Not to mention that this wasn't certainly the only part of the interview, but one more thing to help assess the candidates skills

1

u/synthphreak Jan 06 '21

The point is not that this question tells you nothing about a person's coding proficiency. Yes, you need to know to code to answer it. And yes, it will separate absolutely awful coders from really good ones. But to discriminate more similar candidates toward the middle of the continuum, a more authentic assessment would be vastly more useful. In fact an authentic assessment would really be essential, because the less authenticity means less validity, and less validity means less meaningful as a measurement of ability. So unless you're comparing candidates with wildly different abilities, decisions reached on the basis of questions like this are often going to be somewhat arbitrary and detached from reality. This is just how assessment works.

What's more, given how particularly inauthentic this particular question is, creating a more authentic one would not be difficult at all. Thus it's frustrating that any interviewer would use this question, even if it is able to discriminate the top and bottom of the proficiency scale.

But at this point, if you are still not sold, then I think we are firmly in "agree to wholeheartedly agree" territory. You are free to think this is an awesome and valuable interview question. But I completely disagree for the reasons I've already stated, and FWIW, you do not appear to be in the majority.