Google | Onsite | Minimum of trees needed and their locations

[* H * * * ]
[H * * * * ]
[
* * * * H]
[
* * H * *]

2D matrix, H stands for house, * stands for empty spots and these empty spots can be planted with trees
Find the minium number of trees need to be planted and they will be neighbouring to each house, and the neighbouring condition is 8 directions neighbored

the answer should be ( t stands for trees)
[* H * * * ]
[H t * * * ]
[
* * * t H]
[
* * H * *]

Comments (11)