yongzpub
BAN USER
Comments (3)
Reputation -5
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
def findSubarrays(arr, K):
s_idx, e_idx = 0, -1
total = 0
while s_idx < len(arr) and e_idx < len(arr):
if e_idx == -1 and arr[s_idx] < K:
e_idx = s_idx + 1
elif e_idx == -1:
s_idx += 1
continue
elif arr[e_idx] < K:
e_idx += 1
else:
total += (e_idx - s_idx) * (e_idx - s_idx + 1) // 2
s_idx = e_idx + 1
e_idx = -1
if e_idx != -1:
total += (e_idx - s_idx) * (e_idx - s_idx + 1) // 2
return total
Comment hidden because of low score. Click to expand.
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
- yongzpub June 08, 2020