3 ms·
None 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
by arp242 3y ago
None 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`.