Hacker News new | ask | show | jobs
by dekhn 1169 days ago
presumably regarding the string reversing: they probably wanted a reverse in place (then making sure you handle the even/odd edge condition). however, Python strings are immutable, so you'd have to use a bytearray, but if you have a huge string, converting it to a bytearray, reversing the array, and converting back to a string would likely take longer than having python's string reverse function allocate a new string and write the reverse into it (I would have written both implementations, a timer, and test with increasingly long strings, assuming coderpad).

For the 'e' question: I mean, we learned functions to approximate e in high school. There's a summing series you can do to approximate it- were they expecting you to remember that off the top of your head (if so, you probably dodged a bullet). Otherwise, e*x is its own differential, so i wonder if you could write some terrible routine iterating from a random value to the right one by computing finite differences of various values.

2 comments

If I remember correctly e can be defined as the limit of (1+(1/X)^x as x approaches infinity, so could simply plug in a very large x to approximate. Super simple, but something you have to know, and not very useful in the typical se job. these kind of trivia maths questions are really obnoxious.
> For the 'e' question

They were just expecting exp(x) = \sum_{i=0}^{\inf} \frac{x^i}{i!}.

Depending on the role it might be useless trivia, but it's not exactly an impossibly high bar tbh.

It's a rather stupid question because there are plenty of libraries that can do it better than you could come up with. It's the kind of thing that if I saw a developer wasting their time with at my company, I would immediately fire them, it's akin to rolling your own cryptography.
That series is the definition of the exponential function, literally high-school math.

As I said depends on the role. Normal SWE? Sure, it's trivia and a rather stupid question. For a more science-y or finance role, I'd be very concerned if the candidate doesn't know it.

What about a finance role requires one to know how to inefficiently produce approximations of known constants?
The real question is what else you don't know if you don't even know that...

The power series definition of the exponential function is basic mathematics, and is widely used in financial modeling. This cowboy attitude towards math is just depressing.

An alternative closely related interview question that's a favorite of mine is "please compute the monthly payment for a $200,000 mortgage over 20 years at 3% yearly interest".

You shouldn't be allowed to graduate high school without knowing how to do that, and you'd be surprised how many self-described economists can't answer it.

But the farther from high school the less likely to remember.

Yes I did that in my C++ class in high school. But no I couldn’t do it now and end up with the right answer without some review. I’ve spent a decade and a half doing other things that should matter more than sword drills.