<p>Given an <code>n x n</code><code>grid</code> containing only values <code>0</code> and <code>1</code>, where <code>0</code> represents water and <code>1</code> represents land, find a water cell such that its distance to the nearest land cell is maximized, and return the distance. If no land or water exists in the grid, return <code>-1</code>.</p>
<p>The distance used in this problem is the Manhattan distance: the distance between two cells <code>(x0, y0)</code> and <code>(x1, y1)</code> is <code>|x0 - x1| + |y0 - y1|</code>.</p>