Google | Screening Round
Anonymous User
1646

Given a 2D array with land and water cells, find the area of the largest land-lock.

Slightly different than the usual largest island question. In this variant, the cells which don't have a transitive neighbor ending up in the ocean should be considered as land.

Soln approach.

  1. start with boundary water points, do a dfs on each point and mark the water nodes which will still remain as water. change the rest unvisited water cells to land, calc the largest area of land.
  2. do a dfs on each unvisited water cell and recursively find out if it has a path to the ocean. If not, call a function again to change the whole water bubble to land.

Messed it up real bad. took the second approach (this soln was the first to come to mind, don't know why :'( ). Exited early while trying to find if a water bubble has a path to the ocean. And then didn't bother to maintain a separate state for visited cells which had a path to water. so the whole flow got messed up. shouldn't have followed exit early policy on finding a path to the ocea, then the soln would have worked perfectly. I've solved 800 Qs ot LC, ~500 medium ~200hard. never expected to mess up this bad. not my day :'(

Good luck guys!

Comments (6)
No comments yet.