n1b-algo.blogspot.com
Puzzles, Maths and Algorithms: Finding Relevant Keywords from Large Corpus of Text
http://n1b-algo.blogspot.com/2013/12/finding-relevant-keywords-from-large.html
Puzzles, Maths and Algorithms. December 1, 2013. Finding Relevant Keywords from Large Corpus of Text. Given a large paragraph of words containing n words (separated by space), and k keywords. Find the smallest distance between these keywords in the paragraph. Build an efficient algorithm with O(k) space and O(n log k) running cost. In order to implement this efficiently, we need a hash map and min heap (tree based implementation, not array based). Following is the code to solve this problem. Mapcontains ...