Practice Substring XOR Queries
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
You are given a binary string s, and a 2D integer array queries where queries[i] = [firsti, secondi]. For the ith query, find the shortest substring of s whose decimal value, val, yields secondi when bitwise XORed with firsti. In other words, val ^ firsti == secondi. The answer to the ith query is the endpoints (0-indexed) of the substring [lefti, righti] or [-1, -1] if no such substring exists. If there are multiple answers, choose the one with the minimum lefti. Return an array ans where ans[i] = [lefti, righti] is the answer to the ith query. A substring is a contiguous non-empty sequence of characters within a string.
Source: Substring XOR Queries on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
s = "101101", queries = [[0,5],[1,2]]
[[0,2],[2,3]]
# Example 2
s = "0101", queries = [[12,8]]
[[-1,-1]]
# Example 3
s = "1", queries = [[4,5]]
[[0,0]]
Constraints
Related LeetCode Problems
Practice more problems similar to Substring XOR Queries.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.