Question: You have millions of documents numbered 1,2,3,4,5 ......
You also have a mapping from a word to the list of documents that contains it

Find all the 'pair of words' that occur together in one and only document

Solution: It can be done in O(m+n)/O(Max(m,n)) time complexity and O(m*n bits).
We can calculate a BitMap for the given work by setting all the bits corresponding to each file(number). This BitMap will take O(m) space. The BitMap of both words can be compared in o(1) time (any weird insane comparison). The space requirement can be further scaled down by using base + offset value for any BitMap(can be done based on the range of the file index)