Should i maintain 2 products positive and negative?

And if i keep 2 products one is total positive till now and other negatuve one.So then how will dp be used in this?

hello @pranjalarora98 no there is no need to do this.
You can start taking arrays elements from left to right and multiply them and compare them with a variable max which will be storing the maximum element of the array initially. If we encounter 0, then we update pro variable to 1. Then we do the same for the reversed array. And print the final result. As this is a greedy approach, we need to check for the reversed array also.
Here for your reference i am sharing the code:


if you have any doubt you can ask here:
Happy Learning !!

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.