Posts

Showing posts with the label mapreduce

Top K Frequent Words (Map Reduce) on lintcode online judge

Image
Clash Royale CLAN TAG #URR8PPP Top K Frequent Words (Map Reduce) on lintcode online judge I have met a problem when trying to solve 549. Top K Frequent Words (Map Reduce) on Lintcode. I tried my best to debug but still don't understand why my code cannot be 100% accepted. class Node{ String key; Integer count; Node(String k, Integer c){ key = k; count = c; } } public class TopKFrequentWords { public static class Map { public void map(String tmp_, Document value, OutputCollector<String, Integer> output) { String words = value.content.split(" "); for(String word: words){ if(word.length() > 0) output.collect(word, 1); } } } public static class Reduce { private Queue<Node> min_heap; private int K; private Comparator<Node> nodeComparator = new Comparator<Node>(){ public int compare(Node a...