defnumSubarrayProductLessThanK(nums,k):# moving window# cannot use sort because of the order of number matters heren=len(nums)res=[]# initialize at each stepl,r=0,0prod=nums[l]# moving windowwhiler<n:# update resultifprod<k:iflen(list(nums[l:r+1]))>0:res.append(list(nums[l:r+1]))# expand windowifprod<k:# move windowr+=1# update window stateifr<n:prod*=nums[r]ifnums[r]<k:res.append([nums[r]])else:# shrink windowwhileprod>=k:l+=1# update window stateprod=prod/nums[l-1]# in case the last subarrays are less than kifl<nandprod<k:whilel<n-1:l+=1res.append(list(nums[l:]))returnlen(res)print(numSubarrayProductLessThanK([10,5,2,6],100))