MAXIMUM LENGTH OF SUBARRAY WITH POSITIVE PRODUCT | LEETCODE # 1567 | PYTHON GREEDY SOLUTION

preview_player
Показать описание
In this video we are solving an Amazon interview question: Maximum Length of Subarray with Positive Product (Leetcode 1567).

At first this question seems difficult because there are so many combinations of subarrays you can form but there is a nice and easy way to do it in a greedy manner where we only pass through the input array once. Stay tuned to find out ho
Рекомендации по теме
Комментарии
Автор

So crisp and clear! I think for the `neg = 1 + neg if neg else 0` some comments in the code would've been helpful just to explain whats going on when you revisit the code later on

AnkitaNallana
Автор

I don't understand anything from 4:10

louysatv
Автор

Wow! All the other solutions used dp, this is brilliant

injysarhan
Автор

Omg!! Thankyou so much for making this video. Clear and concise. Wish you all the good luck and success.

jarvispotter
Автор

This solution is genius! Clean and clear! thanks!

fegm
Автор

your logic for not adding 1 when neg is 0 and vice versa isnt correct; neg dosent represent the value of the subarry but the length of the subarray with a negative value; thats a fundamental error in your understanding what your algorithm is doing.

provarence
Автор

Why did you even need the ans variable? You never set it to anything, so it's always going to be zero.

I don't understand how ans = max(ans, pos) worked in your example, because if there was a pos sequence of 4 in the middle, but then the last number was 0, positive would be overwritten to 0. You never set ans = 4 during the for loop, so you should have lost that data and just returned 0 as the answer incorrectly.

I'm not sure how you passed all the test cases. Please explain if I am misunderstanding your code somewhere and why you had the ans variable if you never updated its value

vineethpuli