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

# Bitwise XOR of All Pairings Python Solution

> Tested Python solution for LeetCode 2425 with 21 pytest cases. Generate a practice environment with lcpy.

LeetCode 2425, [Medium](/catalog/medium). Topics: [Array](/catalog/topics/array), [Bit Manipulation](/catalog/topics/bit-manipulation), Brainteaser. [View on LeetCode](https://leetcode.com/problems/bitwise-xor-of-all-pairings/description/).

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

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

## Problem

You are given two **0-indexed** arrays, `nums1` and `nums2`, consisting of non-negative integers. Let there be another array, `nums3`, which contains the bitwise XOR of **all pairings** of integers between `nums1` and `nums2` (every integer in `nums1` is paired with every integer in `nums2` **exactly once**).

Return the bitwise XOR of all integers in `nums3`.

### Examples

```
Input: nums1 = [2,1,3], nums2 = [10,2,5,0]
Output: 13
Explanation:
A possible nums3 array is [8,0,7,2,11,3,4,1,9,1,6,3].
The bitwise XOR of all these numbers is 13, so we return 13.
```

```
Input: nums1 = [1,2], nums2 = [3,4]
Output: 0
Explanation:
All possible pairs of bitwise XORs are nums1[0] ^ nums2[0], nums1[0] ^ nums2[1], nums1[1] ^ nums2[0],
and nums1[1] ^ nums2[1].
Thus, one possible nums3 array is [2,5,1,6].
2 ^ 5 ^ 1 ^ 6 = 0, so we return 0.
```

### Constraints

* 1 \<= nums1.length, nums2.length \<= 10^5
* 0 \<= nums1\[i], nums2\[j] \<= 10^9

## Solution

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

```python theme={"theme":{"light":"github-light","dark":"github-dark"}}
class Solution:
    # Time: O(n + m)
    # Space: O(1)
    def xor_all_nums(self, nums1: list[int], nums2: list[int]) -> int:
        # Each nums1[i] appears in len(nums2) pairings, each nums2[j] in len(nums1);
        # a value XORed an even number of times cancels out.
        result = 0
        if len(nums2) % 2:
            for num in nums1:
                result ^= num
        if len(nums1) % 2:
            for num in nums2:
                result ^= num
        return result
```

## Complexity

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

## Tags

[NeetCode All](/catalog/neetcode).


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