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...
Patrick2788
Mar 23, 2023Silver Contributor
A variation of this challenge: determining longest Win/Loss streaks in a season
'Outcome' - an accumulation of Ws and Ls
=LAMBDA(a,v,IF(v = RIGHT(a), a & v, v))
'Streak function
=Lambda(arr,W_orL,LET(results, SCAN("", arr, Outcome), MAX(LEN(IF(RIGHT(results) = W_or_L, results)))))
PeterBartholomew1
Mar 23, 2023Silver Contributor
Once one can get away with accumulating a scalar value, SCAN does a really good job!
= LET(
streak, DROP(WinLoss,1) = DROP(WinLoss,-1),
count, SCAN(0, streak, LAMBDA(x,y,x*y+1)),
MAX(count)
)
The trouble is that most problems of interest do not fall into that category.