Close
Topic list
Maximum XOR With an Element From Array
HARD
50 mins
Tries
Bit Manipulation
Topics (Covered in this problem)
Problem solved
Skill meter
Tries
-
Bit Manipulation
-
Other topics
Problem solved
Skill meter
Strings
-
Matrices (2D Arrays)
-
Sorting
-
Binary Search
-
-
Stacks & Queues
-
Trees
-
Graph
-
Dynamic Programming
-
Greedy
-
Arrays
-
Binary Search Trees
-
Heap
-

# Maximum XOR With an Element From Array

Contributed by
Hard
Avg time to solve 50 mins
Success Rate 50 %
Share

## Problem Statement

#### Note:

``````1. If all integers are greater than ‘Ai’ in array/list ‘ARR’  then the answer to this ith query will be -1.
``````
Detailed explanation ( Input/output format, Notes, Constraints, Images )
##### Sample Input 1:
``````2
5 2
0 1 2 3 4
1 3
5 6
1 1
1
1 0
``````
##### Sample Output 1:
``````3 7
-1
``````
##### Explanation of sample input 1:
``````In the first test case, the answer of query [1, 3] is 3 because 1^2 = 3 and 2 <= 3,  and the answer of query [5, 6] is 7 because  5 ^ 2 = 7 and 2 <= 6.

In the second test case, no element is less than or equal to 0 in the given array ‘ARR’.
``````
##### Sample Input 2:
``````2
6 3
6 6 3 5 2 4
6 3
8 1
12 4
5 2
0 0 0 0 0
1 0
1 1
``````
##### Sample Output 2:
``````5 -1 15
1 1
``````
Console