Collect maximum coins before hitting a dead end - GeeksforGeeks
Collect maximum coins before hitting a dead end
Given a character matrix where every cell has one of the following values.
'C' --> This cell has coin '#' --> This cell is a blocking cell. We can not go anywhere from this. 'E' --> This cell is empty. We don't get a coin, but we can move from here.
Initial position is cell (0, 0) and initial direction is right.
Following are rules for movements across cells.
If face is Right, then we can move to below cells
- Move one step ahead, i.e., cell (i, j+1) and direction remains right.
- Move one step down and face left, i.e., cell (i+1, j) and direction becomes left.
- Move one step ahead, i.e., cell (i, j-1) and direction remains left.
- Move one step down and face right, i.e., cell (i, j-1) and direction becomes right.
If face is Left, then we can move to below cells
Final position can be anywhere and final direction can also be anything. The target is to collect maximum coins.
Read full article from Collect maximum coins before hitting a dead end - GeeksforGeeks
No comments:
Post a Comment