5 ms·
There are lots of such questions: 1. Reverse a String 2. Find min/max in an array 3. Find/remove duplicates 4. IsPalindrome? 5. Fibonacci (iterative especi
by soham 11y ago
There are lots of such questions:
1. Reverse a String
2. Find min/max in an array
3. Find/remove duplicates
4. IsPalindrome?
5. Fibonacci (iterative especially)
6. Primes (IsPrime, print first few etc)
7. Calculate Factorial
8. Find one missing number from 1 to N.
9. Basic Run length encoding (values and their counts)
etc.
It's trivial to come up with such questions, but it's not trivial to deliver them and judge a person on it. Before asking any of such questions, I'd urge you to exactly know what you want that person to do and have a sense of where they are coming from.
(I do this stuff for a living. About me: http://InterviewKickstart.com http://InterviewKickstart.com)
- Someone1234 11y agoPlus some of these require background knowledge, for example some candidates won't know what a Fibonacci number is or how to calculate one (since they literally haven't covered it for twenty+ years). So be careful what you're ACTUALLY testing.
- DanBC 11y agoThe point of FizzBuzz is that you can give candidates a description of the problem and also give them the mod operator and a sample of its usage and some people would still fail. It would be great if there were some actual research on this. (How many people who claim to be able to program cannot create fizzbuzz in an hour even if you give them a description of modulo) I suspect that a lot of it comes from "programming sheep and goats", which was later withdrawn by its author.
- lsiebert 11y agoYou don't actually need the modulo operator though. Modulo is effectively x - x * (x/y) with integers but you don't even need that. You can do something like this. #include <stdio.h> #include <stdbool.h> int main(void) { int five = 5; int three = 3; int count; bool numprint; for (count = 1; count <= 100; count++){ numprint = true; if (count - three == 0) { three += 3; printf("Fizz"); numprint = false; } if (count - five == 0) { five += 5; printf("Buzz"); numprint = false; } if (numprint) { printf("%d", count); } printf("\n"); } return 0; }
- soham 11y agoYep, point is not to test if they know Fibonacci or prime numbers. If the candidate has forgotten, then you just tell them what those things are. And then expect them to answer it. But here is the (sad?) reality: There will always be someone else applying for the same job, who knows what fibonacci numbers are. You have to be careful to give equal opportunity to both those kinds of people.
- 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.
- Rainymood 11y agoI'm probably going to get lynched for this. I don't have a CS background, but I don't see the difficulty in reversing a string? >string[::-1] Maybe it's because of my limited experience with (so far) Python, and not a lot of exposure to C/C++. What is the answer that interviewers are looking for here?
- georgerobinson 11y agoI think the interviewer would be looking for you to show how you might implement string[::-1] as an algorithm - rather than how to invoke the existing string reversal algorithm in cPython.
- brudgers 11y agoThat's the problem with these questions, the expected answers are steeped in poor engineering practice. When a string needs reversing a library call is always the best first answer. Always. Always. Always. Because the library call has already been debugged.
- bartonfink 11y agoHypothetical response: "Of course, brudgers, and with your experience I'd hope that you would understand that we don't expect you to replace the $LANGUAGE standard library on this job. However, it's still important to us to know that you have some idea how to do that, even if only as a proxy for the sort of work we do expect you to do on this job. So, mind humoring us and taking a stab at it?"
- brudgers 11y ago1. When the absolutely best correct technical answer is unacceptable then how can the question measure technical competence accurately? 2. When the acceptable answers encourage suboptimal engineering practice what in an empirical and non-magical world is the question likely to select for? 3. When an organization is committed to an empirical approach, what is there besides: :does it pass the test? :does it need refactoring? 4. Once one notices how quickly the hypothetical response elided into measuring the willingness of the candidate to produce objectively worse code upon instruction, should you be surprised if the question selects for people? The formal rejecting the correct and best answer is a tribal more steeped in "real men write their own string reversal algorithms" culture. For a junior engineer it sends the message that writing your own string reversal algorithm is a good thing. For a senior engineer, absent the sort of conversation we are having -- and isn't this the sort of conversation one would want to have with a senior engineer? -- the question selects for something other than sound engineering judgement. It's not that the question is bad, per se. It's that when the best objectively correct answer is unacceptable, the belief that it objectively measures competence is a rationalized superstition because it mostly measures, "is this someone who I want to drink beer with?"