You are given a String[] heights
. This is a rectangular
grid representing the height of each square meter of your town. It
contains only lowercase letters ('a' - 'z'), with 'a' meaning low ground
and 'z' meaning high ground. Water flows from a cell to every cell that
shares an edge and is of equal or lower height. The town is surrounded
by high mountains on all sides, so water cannot flow off the map. You
must return the minimum number of pumps that can be placed to ensure
that all rain will eventually flow to some pump.
heights
will contain between 1 and 50 elements,
inclusive.
heights
will contain between 1 and 50
characters, inclusive.
heights
will contain the same number
of characters.
heights
will contain only lowercase letters ('a' - 'z').
{"ccccc", "cbbbc", "cbabc", "cbbbc", "ccccc"} Returns: 1A bowl-shaped area. A single pump in the center is sufficient.
{"cbabcbabc", "cbabcbabc", "cbabcbabc", "cbabcbabc"} Returns: 2Two valleys separated by a ridge. Each valley needs a pump.
{"ccccccccccc", "caaaaaaaaac", "caaaaaaaaac", "caazpppzaac", "caapdddpaac", "caapdddpaac", "caapdddpaac", "caazpppzaac", "caaaaaaaaac", "caaaaaaaaac", "ccccccccccc"} Returns: 2A castle with a central courtyard and a moat. One pump is needed for each.
{"ab", "ba"} Returns: 2Water cannot flow diagonally.