Tap here to switch tabs
Problem
Submissions

Problem: Count the Number of Beautiful Subarrays

Try to solve the Count the Number of Beautiful Subarrays problem.

Statement

You are given a 00 indexed integer array nums. In one operation, you can:

  • Choose two distinct indices i and j in a subarray.

  • Choose a non negative integer k such that the kthk^{ {th}} bit in the binary representation of both nums[i] and nums[j] is 11.

  • Subtract 2k2^k from both nums[i] and nums[j].

A subarray is defined as beautiful if all of its elements can be transformed to 00 after applying this operation any number of times.

Return the total number of beautiful subarrays in nums.

Note: A subarray is a contiguous non empty sequence of elements within an array.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 0≤0 \leq nums[i] ≤106\leq 10^6

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Count the Number of Beautiful Subarrays

Try to solve the Count the Number of Beautiful Subarrays problem.

Statement

You are given a 00 indexed integer array nums. In one operation, you can:

  • Choose two distinct indices i and j in a subarray.

  • Choose a non negative integer k such that the kthk^{ {th}} bit in the binary representation of both nums[i] and nums[j] is 11.

  • Subtract 2k2^k from both nums[i] and nums[j].

A subarray is defined as beautiful if all of its elements can be transformed to 00 after applying this operation any number of times.

Return the total number of beautiful subarrays in nums.

Note: A subarray is a contiguous non empty sequence of elements within an array.

Constraints:

  • 1≤1 \leq nums.length ≤105\leq 10^5

  • 0≤0 \leq nums[i] ≤106\leq 10^6