Baseline: tree as shared

This commit is contained in:
alexm committed 2026-10-05 03:03:38 +00:00
commit 659c03bbf8
1471 files changed
+990535

No files matched your search

+16
View File
@@ -0,0 +1,16 @@
// Kadane: find the best, with an early return for the empty case.
// EXPECT: 6
// EXPECT: -1
FUNCTION MAX_SUBARRAY(Xs : LIST OF INTEGER) RETURNS INTEGER
REQUIRE LENGTH(Xs) >= 1
DECLARE Best, Here : INTEGER
Best <- Xs[0]
Here <- Xs[0]
FOR I <- 1 TO LENGTH(Xs)
Here <- MAX(Xs[I], Here + Xs[I])
Best <- MAX(Best, Here)
NEXT I
RETURN Best
ENDFUNCTION
OUTPUT MAX_SUBARRAY([-2, 1, -3, 4, -1, 2, 1, -5, 4])
OUTPUT MAX_SUBARRAY([-1])