Easy Accepted Solution


  • 0
    N
    public int numSubarrayProductLessThanK(int[] nums, int k) {
    	int count = 0;
    	for (int i = 0; i < nums.length; ++i) {
    		int prod = 1;
    		int j = i;
    		for (; j < nums.length; ++j) {
    			if (prod * nums[j] >= k) {
    				break;
    			}
    			prod *= nums[j];
    		}
    		count += j - i;
    	}
    	return count;
    }
    
    

  • 0
    F

    Wouldn't its time complexity be O(n^2) ?
    (I submitted with same logic in CPP, gives TLE)


  • 0
    C

    Please explain why does j-i lead to the correct solution? What does j-i represent?


  • 0
    P

    @farr3l I agree this is O(n^2) solution and in python also this solution leads to TLE.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.