Skip to content

Bit XOR

Table of Contents

1486. XOR Operation in an Array

1720. Decode XORed Array

2433. Find The Original Array of Prefix Xor

1310. XOR Queries of a Subarray

2683. Neighboring Bitwise XOR

1829. Maximum XOR for Each Query

2997. Minimum Number of Operations to Make Array XOR Equal to K

1442. Count Triplets That Can Form Two Arrays of Equal XOR

2429. Minimize XOR

2527. Find Xor-Beauty of Array

2317. Maximum XOR After Operations

2588. Count the Number of Beautiful Subarrays

  • LeetCode | LeetCode CH (Medium)

  • Tags: array, hash table, bit manipulation, prefix sum

  • nums = [4, 3, 1, 2, 4]
  • In bianry
4 -> 100
3 -> 011
1 -> 001
2 -> 010
4 -> 100
2588. Count the Number of Beautiful Subarrays - Python Solution
from collections import defaultdict
from typing import List


def beautifulSubarrays(nums: List[int]) -> int:
    res, s = 0, 0
    cnt = defaultdict(int)
    cnt[0] = 1

    for x in nums:
        s ^= x
        res += cnt[s]
        cnt[s] += 1

    return res


nums = [4, 3, 1, 2, 4]
print(beautifulSubarrays(nums))  # 2

2564. Substring XOR Queries

1734. Decode XORed Permutation

2857. Count Pairs of Points With Distance k

1803. Count Pairs With XOR in a Range

3215. Count Triplets with Even XOR Set Bits II

Comments