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

Compute, for each index, the product of all numbers to the left times the product of all numbers to the right.

Approach

  1. First pass builds res[i] as the prefix product of elements before i.
  2. Second pass multiplies each res[i] by a running suffix product of elements after i.

Why it works

Every element except nums[i] is included exactly once via prefix * suffix, without division.

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

Idea

Compute, for each index, the product of all numbers to the left times the product of all numbers to the right.

Approach

  1. First pass builds res[i] as the prefix product of elements before i.
  2. Second pass multiplies each res[i] by a running suffix product of elements after i.

Why it works

Every element except nums[i] is included exactly once via prefix * suffix, without division.

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