This is a very standard problem on Trie regarding range query. https://www.codechef.com/problems/MCO16404 What I always see is that while using a Binary Trie for range query, we store a vector in the trie structure to keep track of the position of the number to which a particular bit belongs. Now I was thinking(with respect to the above question) if it was possible to return the index of the element where the xor becomes maximum. Is it actually possible using a trie or do we need some other logic? Any help is appreciated.