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.
I don’t think it’s fair to dock points for asking if the list is sorted. It might feel like a stupid question but clarifying requirements rather than making assumptions is one of the key differentiators between a junior and senior engineer.
>this barely qualifies as a clarifying question in my opinion [...] It is almost irrelevant to the prompt
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.
Asking if the list is sorted was also the very first question that popped up in my head, because it makes the difference between a linear and a quadratic algorithm. Contrary to, for example, having the choice between an n log n algorithm and a linear algorithm, when given the choice between a quadratic and a linear algorithm, it is very rare that the right choice is the quadratic algorithm. (Semi-related: [1])
(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 :)
And if you had a magical oracle that spat out the two numbers if a solution exists, and otherwise told you no solution exists, you would have an O(1) solution.
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).
Clarifying questions may help or not depending on the interviewer. Some want you to clarify, others expect you mostly not to; they'll call that "taking initiative" in that you 'take ownership of the problem' and get something done. Otherwise they'll take that as a request to "spoonfeed you" which is a no-no. You can't tell in advance what they want, and I don't know which attitude is better.
> > given a list of numbers, return two numbers such that one times the other results in 220
> > 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 sorted
Another "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.
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.