Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 2. Assume a grid of m*n. You have to get from the top row to the bottom row.
- Exiting anywhere on the bottom row is fine and starting anywhere on the top row is fine.
- You can move down in one of 3 directions, down left, down and down right.
- Find the optimal path from top to bottom by minimizing the weights you pick up on the way.
- Print weight when you exit.
- [1, 2, 5, 1, 4]
- [8, 4, 7, 2, 6]
- [7, 4, 4, 9, 5]
- Output: 1+2+4=7
- In the above example, From 2 in row one, you can only access 8, 4 and 7.
- From the edge on row one (4), you can only go to down or down left.
- [[5, 9, 1, 3, 8, 2, 6, 4, 0, 7]
- [4, 8, 5, 2, 9, 3, 7, 6, 0, 1]
- [8, 4, 6, 7, 9, 2, 0, 5, 1, 3]
- [3, 5, 4, 9, 2, 0, 6, 7, 1, 8]
- [6, 0, 4, 7, 3, 2, 1, 8, 9, 3]]
Add Comment
Please, Sign In to add comment