You are viewing a single comment's thread. Return to all comments →
Could be even 1, but split into 2 for readability :)
segs = [len(list(j)) for i,j in groupby(a, lambda x:x>k) if not i] return math.comb(len(a)+1,2) - sum(math.comb(i+1,2) for i in segs)
Notes:
answer = count of all subarrays - count of subarrays where all numbers <=k
segs
Seems like cookies are disabled on this browser, please enable them to open this website
Number List
You are viewing a single comment's thread. Return to all comments →
2 line Python solution, 100%
Could be even 1, but split into 2 for readability :)
Notes:
answer = count of all subarrays - count of subarrays where all numbers <=k
.segs
(funny name ikr) array is the lengths of all subarrays where elements are <=k.