qakbot100
BAN USERhash table index by page number. Each entry points to a another hashtable indexed by user number. Each user entry contains the number of times that user visited that page.
unordered_map<int page_number, unordered_map<int user_number, int num_of_visits>>
1. Iterate through the outer hash_map. For each entry, get the size of the user hash_map . If it is 2, output it. Time complexity is O(n).
2. Iterate through the outer hash_map. For each entry, check if the size of the user hash_map is 1, and if it is, check if the number of visits by that one user is 2. If so, then output. Time complexity is O(N).
3. Iterate through the outer hash_map of pages. For each entry, look for user 3 in that user hash map. If found, check if the times visited is 5. If so, then output it.Time Complexity is O(N).
that leaves one big problem.. the above does take into accoun the 'in a day' restriction. To fix that, I would probably have a background job that clears out entries that are older than 24 hours. Run this job every day or as often as you can afford.
The answer is different depending on what is the output of a race: Is it
a) the timings of each horse OR
b) just a ranking
With a, you divide into 5 groups. Run 5 races, 1 per group and now you have the timings of all 25 horses and hence can pick the top 5.
If its b, then it is a little more involved
Yes n(n+1)/2 >= 150. n is approx 17
- qakbot100 February 16, 2015