> ## 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.

# Special Array I Python Solution with Tests

> Tested Python solution for LeetCode 3151 with 22 pytest cases. Generate a practice environment with lcpy.

LeetCode 3151, [Easy](/catalog/easy). Topics: [Array](/catalog/topics/array). [View on LeetCode](https://leetcode.com/problems/special-array-i/description/).

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

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

## Problem

An array is considered **special** if the **parity** of every pair of adjacent elements is different. In other words, one element in each pair **must** be even, and the other **must** be odd.

You are given an array of integers `nums`. Return `true` if `nums` is a **special** array, otherwise, return `false`.

### Examples

```
Input: nums = [1]
Output: true
Explanation: There is only one element. So the answer is true.
```

```
Input: nums = [2,1,4]
Output: true
Explanation: There are two pairs: (2,1) and (1,4), and both contain numbers with different parity.
```

```
Input: nums = [4,3,1,6]
Output: false
Explanation: nums[1] and nums[2] are both odd. So the answer is false.
```

### Constraints

* `1 <= nums.length <= 100`
* `1 <= nums[i] <= 100`

## Solution

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

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
from itertools import pairwise


class Solution:
    # Time: O(n)
    # Space: O(1)
    def is_array_special(self, nums: list[int]) -> bool:
        return all(x % 2 != y % 2 for x, y in pairwise(nums))
```

## 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.