Ctrl K

Sign of the Whole Product

Easy
You are given an integer array factors. Imagine multiplying all of its elements together and determine the sign of the result. Return 1 if the product is positive, -1 if it is negative, and 0 if it equals zero. Note that in most languages the product itself overflows ordinary integer types, so it is better to find the sign without computing it.
Example 1
factors=[3, -2, 5, -1] → 1

The product is 30: two negative factors cancel out, so the answer is 1.

Example 2
factors=[-4, 9, 0, -7] → 0

One of the factors is zero, so the whole product is 0.

Example 3
factors=[-6] → -1

The only factor is negative, so the answer is -1.

Constraints
  • 1 ≤ len(factors) ≤ 2·10⁵
  • -1000 ≤ factors[i] ≤ 1000
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsAdd One to a Digit Array EasyThe Lost Ticket EasyCorner Stamps on a Table EasyBest Product of Three EasyThe Biggest Triangle on the Board Easy
loading Python…
Input
factors=[3, -2, 5, -1]
Expected
1

Run checks the first 3 tests in your browser. Submit checks all 97 tests on the server, hidden ones included.