Given a grid of m*n
where each cell contains either 0 or 1. 0 means obstacle, you cannot pass through a cell with 0. We have to find a path from (0,0)
to (m,n)
that has the maximum number of ones. Allowed moves are right, left, bottom(down). If there is no such path return -1. You cannot pass through the same cell twice. Contraints: 1<=m,n<=400
.
I couldn't think of any approach other than brute force by listing all valid paths. I want optimized approach and solution.