Shortest path to a bus stop
Anonymous User
443

Given a matrix containing A's representing apartments and B's representing bus stops and 1 for cells you can walk through, and -1 for cells that you cannot walk through, which (A,B) pair is closest (which apartment bus-stop pair are closest together)?

EDIT: To make it clearer, the matrix looks something like this (sorry for the bad formattig):

A 1 1 B 1 1
1 -1 1 1 1 1
1 1 1 B 1 1
1 1 1 1 1 1
1 A -1 1 B -1

And you can only go up down left right. Which A is closest to a B? In this case it is clearly the first A, at (0,0) - upper left corner.

This was for a Google interview a long time ago (SWE intern, USA)

Comments (2)