Return a 2D integer matrix of size n*m detailing the shortest path distance to fetch water from the nearest well (back and forth). Cells with 'N', 'W', and '.' have answer 0. Unreachable 'H' should be -1.
{
"n": 3,
"m": 3,
"c": [
[
"H",
"H",
"H"
],
[
"H",
"W",
"H"
],
[
"H",
"H",
"H"
]
]
}[
[
4,
2,
4
],
[
2,
0,
2
],
[
4,
2,
4
]
]{
"n": 2,
"m": 2,
"c": [
[
"H",
"N"
],
[
".",
"W"
]
]
}[
[
4,
0
],
[
0,
0
]
]{
"n": 2,
"m": 3,
"c": [
[
"H",
"N",
"H"
],
[
"N",
"N",
"W"
]
]
}[
[
-1,
0,
2
],
[
0,
0,
0
]
]Sign in to Run Code and Submit