Simulate fixed-shape tiling on a grid

Quick Overview

This question evaluates a candidate's ability to implement grid-based simulation and pattern-matching algorithms, including handling fixed-shape placements, internal holes, bounds checking, collision detection, and explicit scanning/tie-breaking rules.

Simulate fixed-shape tiling on a grid

Company: Uber

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Online Assessment

You are given an empty n-by-m grid and a list of tile patterns, patterns[0..k-1]. Each pattern is a binary matrix (1 = filled cell, 0 = hole) and must be placed exactly as given—no rotation or reflection. Starting with patterns[0], for each pattern i, scan the grid in row-major order (top to bottom, left to right) to find the top-left-most position where all 1-cells of the pattern fit entirely within bounds and only cover currently empty grid cells. If a valid position exists, place the pattern there and write the integer (i + 1) into every covered cell; if no position exists, skip this pattern and continue. After processing all patterns, output the final grid as n rows and m columns, using '.' for cells that remain empty. Implement a function that performs this simulation. Clearly specify your scanning order, tie-breaking, and how you represent patterns. Discuss time and space complexity and edge cases (e.g., patterns with holes, patterns larger than the grid, overlapping attempts).

Quick Answer: This question evaluates a candidate's ability to implement grid-based simulation and pattern-matching algorithms, including handling fixed-shape placements, internal holes, bounds checking, collision detection, and explicit scanning/tie-breaking rules.

|Home/Coding & Algorithms/Uber
Uber logo
Uber
Sep 6, 2025, 12:00 AM
mediumSoftware EngineerOnline AssessmentCoding & Algorithms
10
0

You are given an empty n-by-m grid and a list of tile patterns, patterns[0..k-1]. Each pattern is a binary matrix (1 = filled cell, 0 = hole) and must be placed exactly as given—no rotation or reflection. Starting with patterns[0], for each pattern i, scan the grid in row-major order (top to bottom, left to right) to find the top-left-most position where all 1-cells of the pattern fit entirely within bounds and only cover currently empty grid cells. If a valid position exists, place the pattern there and write the integer (i +

  1. into every covered cell; if no position exists, skip this pattern and continue. After processing all patterns, output the final grid as n rows and m columns, using '.' for cells that remain empty. Implement a function that performs this simulation. Clearly specify your scanning order, tie-breaking, and how you represent patterns. Discuss time and space complexity and edge cases (e.g., patterns with holes, patterns larger than the grid, overlapping attempts).

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...