ANKIT KUMAR’s Post

#100DaysOfCode – Day 10 📌 Today’s Problem: LeetCode 152 – Maximum Product Subarray This one was tricky and super interesting! Unlike sum problems, product problems behave differently because of negative numbers and zeros. Key Learning: A negative number can flip the result So we track both: maxSoFar → maximum product till current index minSoFar → minimum product (important for negative flip) Core Idea: If current number is negative → swap maxSoFar and minSoFar Update both values at each step Keep track of global maximum Complexity: Time: O(n) Space: O(1) Takeaway: Tracking both max & min is the key to handling negative numbers in product-based problems. #LeetCode #Java #DSA #CodingJourney #Day10

  • graphical user interface, application

To view or add a comment, sign in

Explore content categories