713. Subarray Product Less Than K | leetcode daily challenge | DSA | Shashwat Hindi

preview_player
Показать описание
Problem Name:
713. Subarray Product Less Than K

Problem Statement:
Given an array of integers nums and an integer k, return the number of contiguous subarrays where the product of all the elements in the subarray is strictly less than k.

Problem link:

Java Plus DSA Placement Course Playlist:

Java Plus DSA Sheet:

Notes:

Telegram Link:

Ultimate Recursion Series Playlist:

Samsung Interview Experience:

Company Tags:
Facebook | Amazon | Microsoft | Netflix | Google | LinkedIn | Pega Systems | VMware | Adobe | Samsung

Timestamp:
0:00 - Introduction

#ShashwatTiwari #coding​​ #problemsolving​
Рекомендации по теме
Комментарии
Автор

those who wanna check Brute Force Approach :--> (Bhaiya, please pin this comment)
class Solution {
public int nums, int k) {
int n = nums.length; // length of the array
int ans = 0;
for(int i=0; i<n; i++){
int product = nums[i];
if(product < k) ans++;
for(int j=i+1; j<n; j++){
product *= nums[j];
if(product < k) ans++;
if(product >= k) break; // if you not use this line, it fine
}
}
return ans;
}
}

Inspire_with_SM
Автор

Thanks for easy & detailed explaination 🙏🏼

AbhijeetMuneshwar
Автор

Go for 2 pointer approach, where 1st pointer (i) would be fixed and second (j) moves on and multiplies the elements at position (j). If that product is less than K, count++ otherwise stop moving second pointer and start again from i by increasing i++;

utpalkant
Автор

bro i got the solution but i am not able to understand like how the sliding window is working exactly like how would it cover all the subarrays, should i know sliding window concept first for it to understand ?

kanaklata
Автор

bhaiya please ek handwritten notes bana dijiye OOPs ke topic pr mey padh to leta hu but at the end bahut confusion rheta hai OOP mey plz ek handwritten notes.

Inspire_with_SM
Автор

Bhaiya, yeh program bhi sahi h naa?

public class Solution {
public int nums, int k) {
// Variable Sliding Window
int len = nums.length;
int i = 0, j = 0;
long prod = 1;
int cnt = 0;

while (j < len) {
prod *= nums[j];
if (prod < k) {
cnt++;
j++;
if (j >= len) {
i++;
j = i;
prod = 1;
}
} else {
i++;
j = i;
prod = 1;
}
}
return cnt;
}
}

imPriyansh
join shbcf.ru