We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. All Contests
  2. ProjectEuler+
  3. Project Euler #67: Maximum path sum II
  4. Discussions

Project Euler #67: Maximum path sum II

Problem
Submissions
Leaderboard
Discussions

    You are viewing a single comment's thread. Return to all comments →

  • v33vikasgautam
    2 years ago+ 0 comments

    Here is a clojure solution passed both #18 and #67.

    (defn max-path-sum [tri]
      (let [max-sum (fn [a b c] (+ a (max b c)))
            fold-by (fn [bs as] (map max-sum as bs (rest bs)))]
      (first (reduce-right fold-by tri))))
    

    Fold the triangle from bottom, taking the some of current element and max of adjacent elements below.

    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy