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.