Last active
November 19, 2024 05:16
-
-
Save chase-lambert/06a2961201129448dc60e81f8660153b to your computer and use it in GitHub Desktop.
rendezvous with cassidoo challenge: 24.11.17
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns max-the-stock | |
(:require [clojure.test :refer [deftest is]])) | |
(defn max-the-stock [prices] | |
(->> (rest prices) | |
(reduce (fn [[min-price max-profit] price] | |
[(min min-price price) | |
(max max-profit (- price min-price))]) | |
[(first prices) 0]) | |
second)) | |
(deftest max-the-stock-test | |
(is (= (max-the-stock [7 1 5 3 6 4]) | |
5)) | |
(is (= (max-the-stock [7 6 4 3 1]) | |
0))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment