Forum Discussion
Patrick2788
Mar 21, 2023Silver Contributor
Challenge: Find the largest Sub-Array (7 consecutive elements) within a 1,000 element vector
The challenge is simple. Find the sub-array (7 consecutive elements) within a 1,000 array vector with the largest SUM total. The vector was randomly generated and there are no duplicates. My s...
PeterBartholomew1
Mar 21, 2023Silver Contributor
Somewhat longer but with simple steps
= LET(
init, SUM(TAKE(vector,7)),
diff, DROP(vector,7) - DROP(vector,-7),
Addλ, LAMBDA(x,y, x+y),
sum₇, SCAN(init, diff, Addλ),
max₇, MAX(sum₇),
pos₇, 1 + XMATCH(max₇, sum₇),
HSTACK(pos₇, max₇)
)