Question 2
Medium Given an N x N grid with a mouse start S, cheese T, a cat C, impassable water (#), and passable land (.), the mouse moves up, down, left, or right on land only. The safety of a path is the minimum Manhattan distance from any cell on the path to C. Find a path from S to T that maximizes this safety value, and output the maximum value, or -1 if T is unreachable.
Input: N, then N grid rows; exactly one each of S, T, and C.
Example: "3" with rows "S..", ".#.", "C.T" gives 2.
Constraints: 1 <= N <= 500.