[Community Puzzle] Retaining Water

https://www.codingame.com/training/easy/retaining-water

Send your feedback or ask for help here!

Created by @Westicles,validated by @Wontonimo,@selenae and @murrayr.
If you have any issues, feel free to ping them.

It’s a good puzzle but if you don’t pay much attention to the cover and go directly to the IDE, you have to guess a bit cause the Problem doesn’t state much.

For example the whole structure is made of cubes, it’s never said at any point.

Also the word “pool” is a bit misleading, really a pool looks nothing like that.
It looks more like moutain areas with lakes of retained water than one single pool.

But despite that, it was a nice little puzzle.

1 Like

For many puzzles, the tags give an additional hint. Here, the lack of a tag is a hint itself: My first (wrong) reaction when reading the statement was “Hey, a floodfill in the easy category?”. Then I looked at the tags…
Nice puzzle, I liked it!

1 Like

I admit that I used unnecessary floodfills cause I followed my firsy idea which was:
for each level h from 1 to 25:
pour 1 volume of water in lvl h tiles if it doesn’t leak (and mark all tiles that leak)

But indeed a top-bottom “one huge canadair” approach is even simpler and doesn’t require any floodill.

LOL.
Yes, I wasted a bit of water, but conversing water was not part of the design target…

To better understand the puzzle:

What is result for 3x3 all X pool

XXX
XXX
XXX

Does water leak diagonally, what is result for:

XZZ
ZXZ
ZZZ

All X’s would be zero, since you are pouring water on a 3x3 stack of blocks 24 high surrounded by an outside area of zero height. All the water would run off and none would be retained. If the middle value is lower (like in your second example, where the answer would be 2), some water would pool.

I added a note that water does not leak diagonally, just to make it crystal clear.

2 Likes

Ok, Thanks

So result is 2 for:

XZZ
ZXZ
ZZZ

1 Like

The puzzle deserves medium imo, but it’s a good one :+1:

1 Like

very nice puzzle ! I dried my brain to find a correct and naturel way to fill this pool until disaster… congrats.

1 Like

the explanation should probably be a bit clearer, but I had a lot of fun with this puzzle and was a tough one. an extended floodfill problem. Very good idea

1 Like