Company: Flipkart Grid retest_28thjuly
Difficulty: medium
You are given a maze of size m x n . Every cell of the maze is either empty or a wall. A ball is placed on the start cell s and must be brought to rest on the end cell e . There is exactly one s and exactly one e . The ball cannot be pushed. It is moved only by gravity , and the only thing you may do is rotate the whole maze by 90 degrees, either counter-clockwise (a left rotation) or clockwise (a right rotation). Your task is to report C , the number of cells the ball travels over on its way from s to e , with the start cell and the end cell themselves excluded. How the ball moves Gravity always pulls the ball in one of the four grid directions. Measured inside the maze's own frame , gravity starts pointing down (towards increasing row index) and changes with every rotation: a counter-clockwise rotation of the maze moves gravity down -> left -> up -> right -> down ; a clockwise rotation of the maze moves gravity down -> right -> up -> left -> down . Rollin