A community garden coordinator keeps a running signup log: each entry records a volunteer's name together with the plot they tended that day. The same volunteer may show up in the log many times -- for the same plot on different days, or for entirely different plots -- but for scheduling purposes the coordinator only cares about how many distinct volunteers have ever tended each plot. A plot reaches "quorum" once at least 5 different volunteers have tended it at some point, and only quorum plots get scheduled for the joint harvest event. Given the full signup log, determine which plots have reached quorum.
n, the number of signup entries.n lines: each contains two space-separated tokens, a volunteer name and a plot name (both consist only of lowercase English letters and digits, length 1 to 20).Print the names of all plots that have at least 5 distinct volunteers, one per line, sorted in ascending lexicographic (dictionary) order. Print nothing if no plot qualifies.
Example 1
Input
7 alice plotA bob plotA carol plotA dave plotA erin plotA alice plotB bob plotB
Expected
plotA
Explanation
plotA has 5 distinct volunteers (alice, bob, carol, dave, erin), reaching quorum. plotB has only 2 distinct volunteers (alice, bob), which is below 5. So only plotA is printed.
Example 2
Input
12 p1 zplot p2 zplot p3 zplot p4 zplot p5 zplot p1 aplot p2 aplot p3 aplot p4 aplot p5 aplot p6 bplot p7 bplot
Expected
aplot zplot
Explanation
Both zplot and aplot are tended by the same 5 distinct volunteers (p1..p5), so both reach quorum; bplot only has 2 distinct volunteers (p6, p7) and does not qualify. The two qualifying plots are printed in lexicographic order: aplot before zplot.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →