We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents e31282c + 87b5c83 commit ccea1d9Copy full SHA for ccea1d9
Subarray.java
@@ -0,0 +1,29 @@
1
+package Subarray;
2
+public class Subarray_Product_Less_Than_k {
3
+
4
+ public static void main(String[] args) {
5
+ // TODO Auto-generated method stub
6
+ int []arr= {1,2,3,4,2};
7
+ int k=10;
8
+ System.out.println(Product(arr,k));
9
+ }
10
+ public static int Product(int []arr,int k) {
11
+ int si=0;
12
+ int ei=0;
13
+ int p=1;
14
+ int ans=0;
15
+ while(ei<arr.length) {
16
+ //grow
17
+ p=p*arr[ei];
18
+ //shrink
19
+ while(p>=k && si<=ei) {
20
+ p=p/arr[si];
21
+ si++;
22
23
+ //cal
24
+ ans=ans+(ei-si+1);
25
+ ei++;
26
27
+ return ans;
28
29
+}
0 commit comments