Sunflowers. MapReduce.
P.S. While writing this post, I realized this algorithm can be improved. There’s some unnecessary work: first I build a (x, y) → h dictionary, and then I rebuild it into h → [(xi, yi), …]. We can generate the latter format from the start — that’s the first thing to try.
Second: we can water the tallest sunflowers first to reduce waiting time.
If this post gets 10 🔥 reactions, I’ll write one more article with these improvements. Otherwise — it’s homework 😄