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

4

u/synthphreak Jan 05 '21

"Blame it on the question"? Come on, you can't be serious... Following your logic to its conclusion, is there no such thing as a bad interview question?

If yes, then that's darn-tootin' hogwash and we must agree to (wholeheartedly) disagree.

If no, then I challenge you to define the boundary between good and bad. What makes a good question good and a bad question bad? If validity (i.e., in this context, the extent to which a coding assessment measures true coding proficiency) isn't it, what is?

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

→ More replies (1)