> For the complete documentation index, see [llms.txt](https://mayanktyagi3111.gitbook.io/interview-prep/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mayanktyagi3111.gitbook.io/interview-prep/bit-manipulation/untitled-1.md).

# Min XOR value

Given an integer array **A** of **N** integers, find the pair of integers in the array which have minimum `XOR` value. Report the minimum `XOR` value.

**Input Format:**

```
    First and only argument of input contains an integer array A
```

**Output Format:**

```
    return a single integer denoting minimum xor value
```

**Constraints:**

```
2 <= N <= 100 000  
0 <= A[i] <= 1 000 000 000
```

**For Examples :**

```
Example Input 1:
    A = [0, 2, 5, 7]
Example Output 1:
    2
Explanation:
    0 xor 2 = 2
Example Input 2:
    A = [0, 4, 7, 9]
Example Output 2:
    3
```

```java
public class Solution {
    public int findMinXor(int[] A) {
        Arrays.sort(A);
        int minXOR = Integer.MAX_VALUE;
        for (int i = 0; i < A.length - 1; i++) {
            minXOR = Math.min(minXOR, A[i] ^ A[i + 1]);
        }
        return minXOR;
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mayanktyagi3111.gitbook.io/interview-prep/bit-manipulation/untitled-1.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
