Grokking the Coding Interview: Patterns for Coding Questions
Ask Author
Back to course home

0% completed

Vote For New Content
Gaurav Pachpande
Why the while loop of dividing the product?

Gaurav Pachpande

Jul 20, 2023

Why we are having the divsion in while loop? while (product >= target && left < ) { product /= arr[left++]; }

Why we're dividing the product, we can just break the loop right?

0

0

Comments
Comments
E
Ejike Nwude2 years ago

You cannot just break the loop since this is a sliding window and you are trying to exclude left from the running product. So you have to divide by the value at the left pointer then increment the left pointer. This reduces the product to ensure it is less than the targ...