by yankjenets · 6y ago · 0 comments
This is a great clarifying question. Ambiguous from the prompt.
> what shall I return if there are multiple numbers meeting the criteria
This is a decent clarifying question. I think it is better expressed as a clarifying point instead of question--mention to the interviewer your thinking out loud; something like "if there are multiple options, I'll return an arbitrary pair". Ask if they are okay with that.
> is the list sorted
If I were the interviewer, this question would almost make me dock points off of the interviewee. Maybe not that strong as I do try and ensure people are as comfortable and open as possible in asking clarifying questions, but this barely qualifies as a clarifying question in my opinion. It is almost irrelevant to the prompt; if the lists were sorted and the interviewer failed to mention / there was some "trick" that they expected you to clarify, that would be an awful interview question.
That being said, overall agree with the sentiment and yes you should try and always ask clarifying questions and ensure you understand the problem statement.
One of my first internships was punching in 10 meter reams of dot matrix printed numbers.
After several days, during lunch, I casually mentioned how much easier it would have been if the list was electronic.
They said that it was electronic, they just printed it out "for my convenience" so I wouldn't have to constantly keep switching between two apps.
They gave it to me on a floppy, and with the help of an Excel macro I finished two weeks worth of work by the end of the day.
While these whiteboard questions obviously aren't designed to have wider context, I now always appreciate when candidates question the question itself.
(EDIT: after thinking about this more than two seconds, the quadratic algorithm for unsorted input can become n log n by sorting the list, though that takes linear space. This would certainly be a clarifying question.)
The other questions would be less obvious to me, though I'd encounter them while thinking more than 2 seconds about the problem, I suppose.
Or maybe this just outs me as an ex-amateur competitive programmer :)
Just because you can ask a question whose answer makes a drastic difference between the best algorithm involved, doesn't mean it is a good question.
(and note I said "_almost_ make me dock points...". And if the answer to the question was "yes, the list is sorted", I would _certainly_ dock points off of the interviewer/company if I were the interviewee for not giving that context).
Not for a total of 220!
I like the follow up question of "what if they are floats?" to see if the interviewee knows not to use `==` with floats.
If I were the interviewer, this question would almost make me dock points off of the interviewee
Why? Knowing that can be a useful filter to reduce the search time and space, assuming whole numbers only.
If the answer is yes the input is sorted, then that context should have been given in the original prompt as it is a completely different question.
> > is the list sorted?
> this barely qualifies as a clarifying question in my opinion.
Maybe I'm being too charitable but whether or not the list is sorted is very relevant to the first solution that came to my mind as I read the problem.
for i from 1 to n:
for j from i+1 to n:
prod = a[i] * a[j]
if prod == 220:
# found it
if prod > 220:
break
# don't waste time, assumes sortedAnother "clarifying question" in this vein would be "if there is a valid answer, will they be in index 0 and 1 of the list?"
I'm obviously being somewhat facetious here but there's a difference between clearing up an ambiguous part of the question versus asking something that the interviewer gave no indication would be part of the problem.