FastPrepMinimum Obstacle Removal
Problems/Minimum Obstacle Removal

Minimum Obstacle Removal

Uber logoUber● MediumFULLTIMEOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

You are given a 2D grid matrix of one-character strings. A "." is a free cell, a "#" is an obstacle, and a "*" is part of the shape.

All the "*" cells together make one shape. The shape falls straight down, one row at a time, and keeps its form. It can only move into cells that are not obstacles. You can remove obstacles. Find the minimum number of obstacles to remove so that the shape falls all the way to the bottom, which means its lowest cell is in the last row.

If the shape is already in the last row, or there is no shape, return 0.

Complete the function minimumObstacleRemoval in the editor.

minimumObstacleRemoval has the following parameter:

  • String[][] matrix: the grid, where each cell is ".", "#" or "*"

The function returns an int: the minimum number of obstacles to remove.

Function

minimumObstacleRemoval(matrix: String[][]) → int

Examples

Example 1

matrix = [["*", "*", "*", "*"], ["#", "*", ".", "*"], [".", ".", "#", "."], [".", "#", ".", "#"]]return = 4
Example 1 illustration

The shape is a row of four cells with two more cells hanging below it, in columns 1 and 3. Its lowest cells are in row 1, and the last row is row 3, so it must fall 2 rows.

When it falls 1 row, it moves through (1,0), which is an obstacle. When it falls 2 rows, it moves through (2,2), (3,1) and (3,3), which are obstacles too. The other cells on the way are free.

You remove those 4 obstacles, so the answer is 4.

Constraints

  • 1 ≤ N ≤ 300, where N = matrix.length
  • 1 ≤ M ≤ 300, where M = matrix[i].length for every row
  • Each matrix[i][j] is ".", "#" or "*".

More Uber interview questions

  • Random Bingo Card GeneratorONSITE INTERVIEW · Seen Dec 2026
  • Travelers per Consecutive City TripletONSITE INTERVIEW · Seen Dec 2026
  • Worst-Performing Ads by CTR in a Campaign TreePHONE SCREEN · Seen Nov 2026
  • Earliest Time All Users Are ConnectedPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
  • Max Points on a LinePHONE SCREEN · Seen Oct 2026
  • Online Meeting Scheduler with Fixed RoomsONSITE INTERVIEW · Seen Oct 2026
  • Convex Function MinimizationPHONE SCREEN · Seen Oct 2026
  • Meeting Rooms IIPHONE SCREEN · Seen Oct 2026
  • Merge Meeting IntervalsPHONE SCREEN · Seen Oct 2026
  • Minimum Meeting Rooms with AssignmentsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Minimum MovesHarness · OA
  • Shortest Path Around Rectangular ObstaclesDRW · OADRW interview questions
  • Minimum-Cost Path Through a Weighted GridVisa · OAVisa interview questions
  • Minimum Knight MovesMcKinsey & Company · OAMcKinsey & Company interview questions
  • Minimum MovesGoldman Sachs · OAGoldman Sachs interview questions
  • Grid ExplorationIMC Trading · OAIMC Trading interview questions
  • Cookie Monster Minimum Arrival TimeIntuit · OAIntuit interview questions
  • Safest Shortest Path Through a GridSnowflake · OASnowflake interview questions
  • Minimum Cost Path with TeleportationsAmazon · OA
  • Competitive ForagingAkuna Capital · OAAkuna Capital interview questions
All Uber interview questionsSee Uber hiring insights
Saved
class Solution {
    public int minimumObstacleRemoval(String[][] matrix) {
      // write your code here
    }

}
Checking account…