Created
November 21, 2022 16:09
-
-
Save jdh30/f2addf96672de061e5d46b0c0ee553d5 to your computer and use it in GitHub Desktop.
Maximum sum subsequence
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
let maxSumSubseq a = | |
let maxm = Array.fold [a, b -> max a b] 0 a in | |
let rec loop sum i = | |
if i = # a then sum else | |
let ai = Array.get a i in | |
if ai > 0 then loop (sum + ai) (i+1) else loop sum (i+1) in | |
loop 0 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment