<p>Given an array of integers <code>nums</code> and an integer <code>k</code>, return <em>the number of contiguous subarrays where the product of all the elements in the subarray is strictly less than </em><code>k</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> nums = [10,5,2,6], k = 100
<strong>Output:</strong> 8
<strong>Explanation:</strong> The 8 subarrays that have product less than 100 are:
[10], [5], [2], [6], [10, 5], [5, 2], [2, 6], [5, 2, 6]
Note that [10, 5, 2] is not included as the product of 100 is not strictly less than k.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> nums = [1,2,3], k = 0
<strong>Output:</strong> 0
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= nums.length &lt;= 3 * 10<sup>4</sup></code></li>
	<li><code>1 &lt;= nums[i] &lt;= 1000</code></li>
	<li><code>0 &lt;= k &lt;= 10<sup>6</sup></code></li>
</ul>

class Solution:
    def numSubarrayProductLessThanK(self, nums: List[int], k: int) -> int:
        
        prev = 1
        seen = dict()
        seen[1] = 1
        count = 0

        for n in nums:
            print(seen)
            seen_new = {1: 1}
            for s in seen:
                if s * n < k:
                    count += seen[s]
                    if s*n in seen_new:
                        seen_new[s*n] += seen[s]
                    else:
                        seen_new[s*n] = seen[s]
                else:
                    if n*k in seen_new:
                        del seen_new[s*k]

            seen = seen_new
    
        return(count)
                 

        # preprod = [0]*len(nums)
        # prev = 1
        # seen = dict()
        # seen[1] = 1
        # count = 0
        # for i in range(len(nums)):
        #     seen_new = dict(1 = 1)
        #     preprod[i] = nums[i]*prev
        #     prev = preprod[i]
        #     for s in seen:
        #         if int(preprod[i] / s) < k:
        #             count += seen[s]

        #         if preprod[i]/s in seen_new:
        #             seen_new[preprod[i]/s] += 1
        #         else:
        #             seen_new[preprod[i]/s] = 1
        #     seen = seen_new

        # return(count)

        # preprod = [1]*(1+len(nums))
        # prod = 1
        # for i, n in enumerate(nums):
        #     prod = prod*n
        #     preprod[i] = prod
        
        # res = list()
        # li = 0
        # ri = 1

        # count = 0

        # while ri <= len(nums):
        #     if preprod[ri]/preprod[li] < k:
        #         res.append(nums[li:ri])
        #         count += 1
        #         ri += 1
        #     else:
        #         while preprod[ri]/preprod[li] >= k:
        #             li += 1

        # ri = ri -1
        # while li < len(nums)-1:
        #     li += 1
        #     if preprod[ri]/preprod[li] < k:
        #         count += 1
        #         res.append(nums[li:ri])

        # return(count)

            

        
19200