by notmuchtotell · 9y ago · 0 comments
A follow up question could be: "Do you see some problems with running this with big numbers? How would you scale it?"
Beyond that, "it depends" on what you're doing with the results. It's very likely that the developers' time would be better spent removing the factorial from the calculation that uses it, than on making the factorial calculation better at calculating factorials.
Besides that, since you can only meaningfully do 22 different factorials within the bounds of a 64-bit architecture anyway, just pre-calculate the results and make it a lookup table. Returns in O(c).
Not many real-world applications require precision greater than a double, but pure mathematics can calculate millions of [decimal] digits of an irrational number just for amusement. A cryptography application, for instance, would need full precision, whereas an engineering problem might be perfectly fine with fewer significant digits.
For example, if a candidate cannot implement a simple algorithm (like the factorial here), he very likely has poor skills.
If he can implement it without too much trouble, that's a good sign, but he only proved that he probably has some good skills.
Again, the signal is narrow but strong.
Point is, although there might be place for algorithm coding in developer interviews, I am willing to wager a large chunk of my salary that performing well in algorithm interviews doesn't necessarily correlate strongly to performing well on the job.
Why? Performing well on the job needs to be properly defined in it's context first.
Moreover, I think it's highly unprofessional to reinvent the wheel by writing most algorithms for production. I always first look for a bullet proof library for that.
Won't you use a calculator for 345 x 27?
Do you check for nulls in linked list traversals? Potential stack overflows? How about array out of bounds?
If yes, why don't you check their data type?
Do you now see why this process is fucked up? The candidate doesn't know what is your definition of "ok"
No, the process is not fucked up. There is no one right answer. It is CLEAR that the candidate cannot write perfect code in an interview. But it can still provide valuable data.
Basically it can answer to this question: "has the candidate got _any clue_ about programming?". Sometimes that has a lot of value.
Think about a candidate that cannot even write a function that calculates the length of a null-terminated string, for example. Doesn't that test tell you immediately that something is terribly wrong? I've seen these candidates.
When you get over a certain skill threshold, every candidate passes the coding test. After that, it's useless, of course. Then it's probably best to show some code and discuss.
NO SINGLE recruitment test can provide absolute certainty. Coding in interview is just one variable.