Please explain the details

please explain the details

You have four options:

  1. You can come to the new row from left and going right.
  2. You can come to the new row from left and going left.
  3. You can come to the new row from right and going left.
  4. You can come to the new row from right and going right.

You have to calculate the minimum of all the above 4 possible steps.
Now, try to solve the problem.