> ## Documentation Index
> Fetch the complete documentation index at: https://leetcode-py.wisl.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> leetcode-py is a Python LeetCode practice environment generator with one CLI: lcpy. It is not a service or platform.
> Each problem is a directory under leetcode/ with README.md, solution.py, test_solution.py, helpers.py, and playground.ipynb. lcpy gen creates them from JSON templates bundled with the package.
> Examples are backed by tests; copy them verbatim.

# Sign of the Product of an Array

> Tested Python solution for LeetCode 1822 with 20 pytest cases. Generate a practice environment with lcpy.

LeetCode 1822, [Easy](/catalog/easy). Topics: [Array](/catalog/topics/array), [Math](/catalog/topics/math). [View on LeetCode](https://leetcode.com/problems/sign-of-the-product-of-an-array/description/).

Generate this problem as a practice environment: tested reference solution, 20 [parametrized pytest cases](/practice/testing), and a playground notebook:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
lcpy gen -n 1822   # by problem number
lcpy gen -s sign_of_the_product_of_an_array   # by problem name
```

## Problem

Implement a function `signFunc(x)` that returns:

* `1` if `x` is positive.
* `-1` if `x` is negative.
* `0` if `x` is equal to `0`.

You are given an integer array `nums`. Let `product` be the product of all values in the array `nums`.

Return `signFunc(product)`.

### Examples

```
Input: nums = [-1,-2,-3,-4,3,2,1]
Output: 1
```

**Explanation:** The product of all values in the array is 144, and signFunc(144) = 1.

```
Input: nums = [1,5,0,2,-3]
Output: 0
```

**Explanation:** The product of all values in the array is 0, and signFunc(0) = 0.

```
Input: nums = [-1,1,-1,1,-1]
Output: -1
```

**Explanation:** The product of all values in the array is -1, and signFunc(-1) = -1.

### Constraints

* 1 \<= nums.length \<= 1000
* -100 \<= nums\[i] \<= 100

## Solution

Reference implementation from [solution.py on GitHub](https://github.com/wislertt/leetcode-py/blob/main/leetcode/sign_of_the_product_of_an_array/solution.py), full suite in [test\_solution.py](https://github.com/wislertt/leetcode-py/blob/main/leetcode/sign_of_the_product_of_an_array/test_solution.py):

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
class Solution:
    # Time: O(n)
    # Space: O(1)
    def array_sign(self, nums: list[int]) -> int:
        sign = 1
        for num in nums:
            if num == 0:
                return 0
            if num < 0:
                sign = -sign
        return sign
```

## Complexity

| Time | Space |
| - | - |
| O(n) | O(1) |

## Tags

[NeetCode All](/catalog/neetcode).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.