Sanjay gives you two integers $$$N$$$ and $$$X$$$, find the maximum Bitwise Xor value of a pair of integers in the range $$$[1, N]$$$. However, the chosen pair must not include the integer $$$X$$$.
You need to determine the maximum Bitwise Xor value achievable by choosing two distinct numbers $$$a$$$ and $$$b$$$ $$$(1 \leq a, b \leq N, a \neq X , b \neq X, a \neq b)$$$
26 16 2
7 7
Sanjay gives you a sequence of $$$n$$$ integers is given $$$a_1$$$, $$$a_2$$$, .. $$$a_n$$$. You need to process $$$q$$$ queries of two types.
The sequence supports the following two types of operations:
181 2 3 4 5 6 7 882 101 1 61 2 62 101 1 51 2 61 3 71 4 1
5 6 7 1 10 10 10 10
$$$[1 ,2 ,3 ,4 ,5 ,6 ,7 ,8]$$$ $$$\xrightarrow[]{1}$$$ $$$[10 ,10 ,10 ,10 ,10 ,10 ,10 ,10]$$$ $$$\xrightarrow[]{2}$$$ $$$[6 ,10 ,10 ,10 ,10 ,10 ,10 ,10]$$$ $$$\xrightarrow[]{3}$$$ $$$[6 ,6 ,10 ,10 ,10 ,10 ,10 ,10]$$$ $$$\xrightarrow[]{4}$$$ $$$[10 ,10 ,10 ,10 ,10 ,10 ,10 ,10]$$$ $$$\xrightarrow[]{5}$$$ $$$[5 ,10 ,10 ,10 ,10 ,10 ,10 ,10]$$$ $$$\xrightarrow[]{6}$$$ $$$[5 ,6 ,10 ,10 ,10 ,10 ,10 ,10]$$$ $$$\xrightarrow[]{7}$$$ $$$[5 ,6 ,7 ,10 ,10 ,10 ,10 ,10]$$$ ,$$$\xrightarrow[]{8}$$$ $$$[5 ,6 ,7 ,1 ,10 ,10 ,10 ,10]$$$
Sanjay is focusing on proposing questions. He wants to ensure that he and his soulmate are as far apart as possible on a 1D line. He needs your help to solve this problem optimally.
On a 1D line, two people are at Sanjay $$$(x_1)$$$ and his soulmate $$$(x_2)$$$ with $$$x_1 \lt x_2$$$.
Initially you have $$$n$$$ pairs $$$(l, r)$$$ such that $$$l \leq r$$$, $$$l \leq x_2$$$, and $$$x_1 \leq r$$$.
For each pair, you can perform:
Additionally, exactly once, you must perform both operations (1) and (2) on the same pair. For the remaining pairs, you must choose to perform either operation (1) or (2).
Your task is to find the maximum possible value of $$$x_2 - x_1$$$ after performing the operations optimally, ensuring that Sanjay and his soulmate are as far apart as possible.
2 2 2 9 1 8 3 7 3 10 60 11 58 12 59 13 59
5 47
Sanjay has an undirected tree with $$$n$$$ nodes, where each node is labeled from $$$1$$$ to $$$n$$$. Each node $$$u$$$ also has an associated integer value $$$val_u$$$. For each node $$$u$$$, determine the shortest distance to a node $$$v$$$ $$$(v \neq u)$$$ such that:$$$ \implies $$$ ($$$val_u$$$ $$$\&$$$ $$$val_v$$$) $$$ \neq $$$ $$$max(val_u , val_v)$$$.
___________________________________________________________
263 7 2 5 8 11 22 33 44 55 652 2 2 2 25 34 32 51 2
1 1 1 1 1 1 -1 -1 -1 -1 -1