5 ms·
>8. Find one missing number from 1 to N. That's a horrible interview question, because it's easy if you know the arithmetic/xor trick. If you haven't seen it
by fsk 11y ago
>8. Find one missing number from 1 to N.
That's a horrible interview question, because it's easy if you know the arithmetic/xor trick. If you haven't seen it before, it's harder than what you'd expect a candidate to get on an interview.
- soham 11y agoThe arithmetic here is high-school arithmetic. Even if one doesn't know it, it is easy to derive/see it during the interview. Not saying it's an excellent question. Just saying it's pretty much as quirky/inefficient as any other technical interview question.
- fsk 11y agoMost interview questions can be summarized as: 1. Have you heard this question before? or 2. What number am I thinking of? You'd be surprised how often (2) comes up. The interviewer is looking for a specific answer, and any other answer is wrong.
- lsiebert 11y agoYou don't need to use xor, unless you are trying to be clever or have a number representation already in bits: n(n+1)/2 - sum(array) is your answer and is O(n);
- fsk 11y agoxor is the solution that uses the least storage I heard a variation of that question that began "using the least possible storage space...", with the goal being to find the xor solution. The arithmetic solution also has problems when you overflow an integer, although that matters more if your CPU has 16 bit ints.