Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
For each <code>nums[i]</code>, complement it (for each bit, if it is 1, it becomes 0 and vice-versa).
Instead of finding the maximum Hamming distance from <code>x = nums[i]</code>, let's think of finding the minimum Hamming distance from the complement of <code>x</code> to any element of the array.
Create a graph with <code>V = {0, 1, ..., 2<sup>m</sup> - 1}</code>. Put an edge between two vertices if they differ in exactly one bit.
Run a multi-source BFS from elements of <code>nums</code>.
Now for each <code>x</code>, to find its minimum Hamming distance from elements of the array, simply calculate its shortest path from array elements.