All Posts

Leetcode 2564: Substring XOR Queries

You are given a binary string s and a 2D array of queries. Each query is represented as [firsti, secondi], where firsti and secondi are integers. For each query, you need to find the shortest substring of s whose decimal value XORed with firsti equals secondi.

In other words, find a substring whose decimal value, when XORed with firsti, results in secondi. If such a substring exists, return its starting and ending indices (0-indexed). If no such substring exists, return [-1, -1].

If there are multiple valid substrings, return the one with the smallest starting index.

Leetcode 2568: Minimum Impossible OR

You are given a 0-indexed integer array nums. A number x is expressible from nums if there exists a subsequence of elements in nums whose bitwise OR equals x. Your task is to return the smallest positive integer that cannot be expressed as the bitwise OR of any subsequence from nums.

Leetcode 2571: Minimum Operations to Reduce an Integer to 0

You are given a positive integer n. You can perform the following operation any number of times: Add or subtract a power of 2 from n. Your goal is to find the minimum number of operations required to make n equal to 0.

Leetcode 2572: Count the Number of Square-Free Subsets

You are given a positive integer array nums. A subset of the array nums is square-free if the product of its elements is a square-free integer. A square-free integer is an integer that is not divisible by any perfect square other than 1. Return the number of square-free non-empty subsets of the array nums. Since the answer may be too large, return it modulo 10^9 + 7.

Leetcode 2588: Count the Number of Beautiful Subarrays

You are given a 0-indexed integer array nums. In one operation, you can choose two indices and subtract a power of two from both elements at those indices. A subarray is considered beautiful if you can make all of its elements equal to zero by applying the operation any number of times. Your task is to return the number of beautiful subarrays in nums.

Leetcode 2595: Number of Even and Odd Bits

Given a positive integer n, return an array containing the number of 1 bits at even indices and odd indices in the binary representation of n. The binary digits are indexed from right to left, starting at index 0. The first element of the array should represent the number of 1 bits at even indices, and the second element should represent the number of 1 bits at odd indices.