All Tracks Data Structures Arrays 1-D Problem

Minimum AND xor OR
Tag(s):

1-D, Arrays, Data Structures, Operators, Sorting

Problem
Editorial
Analytics

You are given an array \(A\) of \(N\) integers. Determine the minimum value of the following expression for all valid \(i,j\):

\((A_i \ and \ A_j) \ xor \ (A_i \ or \ A_j)\), where \(i \ne j\).

Input format

  • First line: A single integer \(T\) denoting the number of test cases
  • For each test case:
    • First line contains a single integer \(N\), denoting the size of the array
    • Second line contains \(N\) space-separated integers \(A_1,A_2,...,A_n\)

Output format

For each test case, print a single line containing one integer that represents the minimum value of the given expression

Constraints

\(1 \le T \le 10^3\\ 1 \le N \le 10^5\\ 0 \le A_i \le 10^9\)

Note: Sum of \(N\) overall test cases does not exceed \(10^6\)

SAMPLE INPUT
2
5
1 2 3 4 5
3
2 4 7

SAMPLE OUTPUT
1
3

Explanation

For test case #1, we can select elements \(2\) and \(3\), the value of the expression is \((2 \ and \ 3) \ xor \ (2 \ or \ 3) = 1\), which is the minimum possible value. Another possible pair is 4 and 5.

For test case #2, we can select elements 4 and 7, the value of the expression is \((4 \ and \ 7) \ xor \ (4 \ or \ 7) = 3\), which is the minimum possible value.

Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: Bash, C, C++, C++14, C++17, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, Java 14, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, Python 3.8, R(RScript), Racket, Ruby, Rust, Scala, Swift-4.1, Swift, TypeScript, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

HackerEarth

Challenge Name

March Circuits '20

OTHER PROBLEMS OF THIS CHALLENGE
Notifications
View All Notifications

?