Facebook | Phone screen | Shortest Distance from All Houses

4174
May 30, 2019
Jul 26, 2019

You’ve been tasked to help a village find the best place to install a new well. You’re given a 2D grid where cells can be empty, a house, or a tree. People can walk up, down, left and right, but they can’t walk through trees. Place the well that minimizes the total sum distance from all the houses.

=. =. =. =
= H T =
= H T =
= = H =

Comments (7)