I believe that the idea is this:
There is a set of (sorted?) arrays, which contain numbers. Given a number (say, 1) and the number of pairs (say, 3), find the 3 combinations of two numbers, one of which is one, occurring in each array. Note that the 4 in the first array in the data set above does not form a pair with the 1 in the second array because they're not part of the same array. But the 1 and 4 in the last four arrays DO count.
To me, the solution could come from extensive pre-processing (i.e. creation of an extensive hash data structure, which would allow really fast lookup but which would make it hard to preprocess) or to do a lookup for each entered query. I would go for the first option.
I do have a few questions, however.
- Do numbers ever repeat w/i an array, like
1 1 2 3 4 4 5 6
- You note that (1,5), (1,6), and (1,4) all appear four times, so your query for the 3 highest makes sense. What happens, though, if (1,3) also had 4 entries? If you ask for the top 3, should it just discard one pair randomly.
| [reply] |