Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

nums =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

Negative numbers flip max/min products, so track both.

Approach

Scan array maintaining:

  • curMax = max product ending here
  • curMin = min product ending here If x < 0, swap curMax and curMin, then update.

Why it works

Any max product ending at i is either x alone or extends a previous product; negative values can turn a previous minimum into a maximum.

Code
Loading...
Complexity
Time: O(n)
Space: O(1)
Solution
Updated: 2026-02-23

Idea

Negative numbers flip max/min products, so track both.

Approach

Scan array maintaining:

  • curMax = max product ending here
  • curMin = min product ending here If x < 0, swap curMax and curMin, then update.

Why it works

Any max product ending at i is either x alone or extends a previous product; negative values can turn a previous minimum into a maximum.

Code
Loading...
Complexity
Time: O(n)
Space: O(1)