4 ms·
My naive 2 minutes solution : (reduce #(assoc %1 %2 (inc (get %1 %2 0))) {} "abcaaabcccaabrrcb") EDIT: While it's shorter and (in
by Raphael_Amiard 16y ago
My naive 2 minutes solution :
(reduce #(assoc %1 %2 (inc (get %1 %2 0)))
{}
"abcaaabcccaabrrcb")
EDIT: While it's shorter and (in my opinion) a lot clearer than the OP's solution, it's also consistently faster. Functionnal code and composition is cool, but i think the author got trapped into making his code beautifull, or maybe just into the wrong algorithm for the job. It happened to me before in clojure and other functional languages
- Lozzer 16y agoOr as mentioned in the comments (frequencies "abcaaabcccaabrrcb") with some optional sorting if that's required.