Skip to content

Instantly share code, notes, and snippets.

@craftybones
Created February 1, 2017 15:29
Show Gist options
  • Save craftybones/323d25b5038e7df654b0201973ac6d29 to your computer and use it in GitHub Desktop.
Save craftybones/323d25b5038e7df654b0201973ac6d29 to your computer and use it in GitHub Desktop.
(defn max-adjacents [coll]
(map max coll (rest coll)))
(defn sum-of [prev current]
(map + current (max-adjacents prev)))
(defn max-path-sum [tree]
(first (reduce sum-of (reverse tree))))
;; To test use the following
;; (def tree [[3]
;; [7 4]
;; [2 4 6]
;; [8 5 9 3]]
;; (max-path-sum tree)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment