import java.util.*;
public class Main {
public static void main (String args[]) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
long pp = 1, np = 1, max = Integer.MIN_VALUE;
boolean hasZero = false, hasPos = false;
for(int n=0; n<t; n++){
int i = s.nextInt();
if(i > 0){
hasPos = true;
pp *= i;
if(np != 1) np *= i;
} else if( i < 0) {
long temp = pp;
pp = Math.max(1, np * i);
np = temp * i;
} else {
np = pp = 1;
hasZero = true;
}
if(max < pp) max = pp;
}
if(max == 1){
if(hasPos){
System.out.println(max);
return;
}
if(hasZero){
System.out.println(0);
return;
}
}
System.out.println(max);
//return max;
}
}
What's wrong in the solution. One of the test case failing
Hey @subodh_dreaming_faang,
The only issue your code is having when it has to deal with only single element present in the array. Have just added an if condition in it, now it will pass test cases
If you want to know what test case were you missing it is:
1
-1
Expected answer: -1
Your code is giving: 1
Rest everything looks great
Hope it helps