In this post, we are going to discuss leetcode 1368 — Minimum Cost to Make at Least One Valid Path in a Grid, which is recently asked in Google interviews.
Problem Analysis
Given an
m x n
grid. Each cell of the grid has a sign pointing to the next cell you should visit if you are currently in this cell. The sign ofgrid[i][j]
can be:
1
which means go to the cell to the right. (i.e go fromgrid[i][j]
togrid[i][j + 1]
)2
which means go to the cell to the left. (i.e go fromgrid[i][j]
togrid[i][j
…