Google Onsite matrix traversal BFS/DFS
Anonymous User
3749

Had my first onsite screening for Google (1 round for an hour) and got the question.

Given a matrix where land is marked as "X", water is marked as ".". A "." is considered an ocean if it's unbounded on atleast one side. A coast is any land directly connected to the ocean. Water grid bounded on all sides by land is considerd a lake.
Find if a given grid (co-ordinate) is a coast.

Eg:
x x x x x x
. . . x . x . .
. . . x x . x .

isCoast(1, 3) returns True

. . . . . . . .
x x x . x .
x . x x . x .
x x x . x x
x x x x x x

isCoast(3, 2) returns False

Comments (8)