Some error occured while loading page for you. Please try again.
Sort 7 Discussions, By:
Please Login in order to post a comment
Python2 template is broken: the first line of the input should be interpreted before the mapreduce (as in the other templates), so that the mapper receives the set name as the key instead of the line number..
Regarding the Java version.
Could you explain why JSONObject and some other wrappers are used?
I have tried to simplify the initial version provided:
Please mention the significance of LinkedHashMap in the template of java, why do we need the insertion order maintained in the inputdata json
Although R and S are mentioned as set, it would still be better to explicitly state that the numbers for each of the collections won't be repeated.
Also, line 176: "intermediate.put(key,temp);" (in Java code) is confusing, please remove it from the template.
Rest the code is elegant, beautiful and self-explainatory to say the least. Kudos to team Hackerrank for introducing such a challenge. :)
Think carefully about the keys used for the map; you can easily create intermediate values which already indicate the sets each integer appears in - no need to do this in the reduce.
There is a mistake within the Python code: pref using sys.stdin.read().splitlines() into the for loop (reading JSON file) not to add \n or EOF into the keys.
This code will only work provided, R and S are set themselves. But I was wondering if we get to code the entire map and reduce method by ourselves then this would have been pretty good challanges. But all I see here is fill in one value which is very simple!
@Moghaak yes you are right but we should understand the program flow and map reduce paradigm to insert that value
In fact you have to do more than just fill the gaps. You should add a few code before mapReducer.emitIntermediate(?, ?) and mapReducer.emit((?, ?)). The idea is that you have to map in some way to facilitate the reduce operation after. In fact reduce() exploits previously created dictionary (map) and performs checks to produce the final "reduced" dictionary.
Hope it's helpful!
No more comments