aboutsummaryrefslogtreecommitdiff
path: root/bitwise_xor_pairings.py
blob: bc1b91766f0bfc3eb7c401060c2144a2a173b6af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 2425. Bitwise XOR of All Pairings
from functools import reduce
from operator import xor

"""
you are given two 0-indexed arrays 'nums1' and 'nums2', consisting of
non-negative integers. there exists 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'
"""


class Solution(object):
    def xorAllNums(self, nums1, nums2):
        """
        :type nums1: List[int]
        :type nums2: List[int]
        :rtype: int
        """
        return (len(nums1) % 2 * reduce(xor, nums2)) ^ (
            len(nums2) % 2 * reduce(xor, nums1)
        )


if __name__ == "__main__":
    obj = Solution()
    print(obj.xorAllNums(nums1=[2, 1, 3], nums2=[10, 2, 5, 0]))
    print(obj.xorAllNums(nums1=[1, 2], nums2=[3, 4]))