5 ms·
> can I multiply a number by itself This is a great clarifying question. Ambiguous from the prompt. > what shall I return if there are multiple numbers meetin
by yankjenets 6y ago
> can I multiply a number by itself
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.
- laumars 6y agoI 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.
- collyw 6y agoThis is the problem with interviews, it seems many of them are a circlejerk for the interviewer rather than actually trying to get a realistic idea of the candidate is up to the job.
- throwaway_pdp09 6y agoClarifying 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.
- koala_man 6y ago>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.
- tomsmeding 6y agoAsking 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 :) [1]: https://accidentallyquadratic.tumblr.com/ https://accidentallyquadratic.tumblr.com/
- wetmore 6y agoFairly sure you can do it in linear time and space without sorting.
- yankjenets 6y agoAnd 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).
- contingencies 6y agoCan I multiply a number by itself. This is a great clarifying question. Not for a total of 220!
- tomsmeding 6y agoWho said that the inputs where integers? :)
- amirkdv 6y agoFunny how everyone here, myself included, assumed the numbers were integers! I like the follow up question of "what if they are floats?" to see if the interviewee knows not to use `==` with floats.
- pmontra 6y ago220 = 2 * 2 * 5 * 11. There must be 2 * sqrt(5) * sqrt(11) in that list of numbers. It's about 14.8323969742. Easy to test for it.
- amirkdv 6y ago> > 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
- yankjenets 6y agoMy point was more it is just a different problem. 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.
- artmageddon 6y ago> > is the list sorted 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.
- yankjenets 6y agoBecause the answer should be an obvious "no it is not guaranteed to be sorted". 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.
- artmageddon 6y agoIt is, but some interviewers can be intentionally vague.