Answers for "max product subarray"

C++
0

find maximum product subarray

// Java program to find maximum product subarray
import java.util.*;
class GFG{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
// length of Array 
int n=sc.nextInt();
// Creating Array of Size n 
int[] arn=new int[n];
// User Input for storing elements in Array
for(int i=0;i<n;i++){
arr[i]=sc.nextInt();
}
// Creating to variable mul for multiplication and temp for stroing mul value
int mul=1,temp=0;
for(int i=0;i<n;i++){
mul=arr[i]*mul;
if(mul==0)
mul=l;
if(mul>temp){
temp=mul; }
}
System.out.print(temp);
}
}
// This code is contributed by snipereagle99 (Kuldeep Singh)
Posted by: Guest on July-09-2021

Browse Popular Code Answers by Language