FastPrepDrop a Connected Figure Through Obstacles

Drop a Connected Figure Through Obstacles

ZipRecruiter logoZipRecruiter● MediumFULLTIMENEW GRADOA
Learn

Problem statement

A rectangular grid uses . for empty, # for obstacles, and F for one orthogonally connected rigid figure.

Move the complete figure downward as far as possible without any figure cell leaving the grid or overlapping an obstacle. Return the final grid.

Function

dropFigure(grid: String[]) → String[]

Examples

Example 1

grid = [".F.",".F.","...",".#."]return = ["...",".F.",".F.",".#."]

The figure falls one row before its lower cell would hit the obstacle.

Example 2

grid = ["F..","..."]return = ["...","F.."]

The figure falls to the bottom.

Constraints

  • 1 <= rows,columns <= 200

More ZipRecruiter problems

See ZipRecruiter hiring insights
public String[] dropFigure(String[] grid) {
    // Write your code here.
}
grid[".F.",".F.","...",".#."]
expected["...", ".F.", ".F.", ".#."]
Checking account…