3 ms·
You also need to add tests as well as decide whether to break the existing API, or to create a new function in the API, in which case you need to design it. Do
by JohnKemeny 3y ago
You also need to add tests as well as decide whether to break the existing API, or to create a new function in the API, in which case you need to design it. Do you add room for future support for division? Exponentiation? Knuth's up-arrow notation? Logarithms? What about integer factorization and discrete log? What about factorial? Sooo many choices. I can easily waste 3 hours in just 1 hour.
- arp242 3y agoNone of that is in the description. You are spectacularly over-engeering things. A test might be useful, but I took a quick peek at the source and it really is as straight-forward as I suspected it would be: the input is already tokenized and you can just add a new entry in a large, if .. else if tree, write a multiplication function, and that's pretty much it. You can just test it by started memcached and sending it commands. I'd whip up a quick patch, but the tar.gz is 14 years old and doesn't compile with latest clang without twiddling -W flags that don't seem to apply, and the git copy doesn't compile due to autoconf woes (sigh...) Messing around with autoconf is not my idea of fun and too much pain for a HN comment, so whatever. But you really don't need 3 hours if you vaguely know what you're doing and are a competent C programmer (which I am only barely).
- JohnKemeny 3y agoI was obviously just kidding with the other operations, but the API issue is relevant.
- arp242 3y agoRight so – that wasn't clear to me. You'd be surprised how much some people will over-engineer some interview questions like that (even when you very explicitly tell them to use the simplest thing possible). The memcached protocol really is as simple as "CMD [params]", all of which is parsed for you, and this API is just "MULT num1 num2". There are no tricky bits or hidden complexities here as far as I can see.
- JohnKemeny 3y agoYes, the protocol is obvious, but you need to look at `do_add_delta`.
- yobbo 3y agoA little hint: multiplication and addition are associative which is why they make sense as atomic operations. (Although allowing both multiplication and addition in the protocol breaks this ...) If you read the introduction and then spend extra hours doing "other things" (that are bad), it could count against you.