Walking to a friend in the plaza

Write code · Medium · §9.3 Nearest first

The map of a plaza in a metaverse social network is given as the grid plaza. '.' is a cell an avatar can walk on, '#' is a wall, 'A' is the cell where my avatar stands, and 'B' is the cell where my friend's avatar stands. In one step, an avatar moves to an adjacent cell above, below, to the left, or to the right. It cannot move into a wall or off the map.

Complete the function solution, which returns the smallest number of steps my avatar needs to reach my friend's cell. If my avatar cannot reach my friend, return -1.

Function

solution(plaza)

Constraints

Examples

plazaresult
['#####', '#A..#', '#.#.#', '#..B#', '#####']4
['#####', '#A#B#', '#.#.#', '#...#', '#####']6

Starter code

def solution(plaza):
    answer = 0
    return answer

Solve this problem in your browser

Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.