Two robbers break into an antique shop and decide to steal an old famous sofa. The shop is quite messy, so this may be a difficult task.
You are given the floorplan of the shop in the String[] plan, with the first element of plan corresponding to the top row of the floorplan. Each piece of furniture is labeled with a distinct uppercase letter ('A'-'Z'). The famous sofa is labeled with 'A'. Empty cells are marked with '.'. You can push any of the pieces of furniture in any of the four directions (right, up, left and down) one cell at a time as long as it doesn't collide with any other furniture or with walls.
Your objective is to move the famous sofa so that at least one of its cells is in the top row.
Return the least number of pushes required to accomplish this goal, or -1 if it is not possible.
|