4 ms·
Make sure you ask for the O(1) solution, because if someone's production instincts are to write (fn [l h] (* (dec (- h l)) (/ (+ h l) 2)))
by dropit_sphere 11y ago
Make sure you ask for the O(1) solution, because if someone's production instincts are to write
(fn [l h]
(* (dec (- h l))
(/ (+ h l) 2)))
whenever they need to sum between two numbers, then I'd argue they're a worse programmer than someone who just writes `(reduce + (range (inc l) h))`. Programmer time is expensive, and linear time is, for 99% of ranges most devs will encounter, just fine.
- talideon 11y agoThat is very much dependent on the circumstances. Besides, this is pre-interview weeding question, and if they give the O(1) answer, that gives use something to talk about in the interview.