PracHub
QuestionsLearningGuidesInterview Prep
|Home/Coding & Algorithms/Amperity

Render Overlapping Rectangles on an ASCII Canvas

Last updated: Jul 28, 2026

Quick Overview

Render bordered and filled rectangles onto a fixed ASCII canvas, clipping safely and honoring input-order overwrites. Handle negative coordinates, fully hidden shapes, one-cell dimensions, trailing spaces, overlap behavior, and a canvas of up to one million cells.

  • medium
  • Amperity
  • Coding & Algorithms
  • Software Engineer

Render Overlapping Rectangles on an ASCII Canvas

Company: Amperity

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Onsite

# Render Overlapping Rectangles on an ASCII Canvas Implement `render_canvas(width, height, rectangles)`. The canvas initially contains spaces and is returned as a list of `height` strings, each of length `width`. Each rectangle is `(x, y, w, h, border_char, fill_char)`, where `(x, y)` is its upper-left corner, `w` is its width, and `h` is its height. Draw the outermost cells with `border_char` and interior cells with `fill_char`. Coordinates may place part or all of a rectangle outside the canvas; clip safely. Rectangles are drawn in input order, so later rectangles overwrite earlier pixels wherever they overlap. ## Constraints - `0 <= width, height <= 1000` - `1 <= w, h <= 1000` - `x` and `y` may be negative. - `border_char` and `fill_char` are single printable characters. - The total canvas area is at most `10^6` cells. ## Example For a `5` by `4` canvas and rectangle `(1, 1, 3, 2, '#', '.')`, return: ```text ### ### ``` A one-cell-wide or one-cell-high rectangle consists entirely of border cells. ## Clarifications Canvas coordinates use zero-based columns and rows. Preserve trailing spaces in every returned row. Explain how clipping prevents invalid indexing without changing whether a visible cell is a border or interior cell of the original rectangle. ## Hints Intersect each rectangle's coordinate range with the canvas before visiting pixels, but compute border status in the rectangle's original coordinates. ## Extensions - Return only changed regions for a very large sparse canvas. - Support transparency or z-indexes. - Add tests for total clipping, corner clipping, thin rectangles, and overwrite order.

Quick Answer: Render bordered and filled rectangles onto a fixed ASCII canvas, clipping safely and honoring input-order overwrites. Handle negative coordinates, fully hidden shapes, one-cell dimensions, trailing spaces, overlap behavior, and a canvas of up to one million cells.

|Home/Coding & Algorithms/Amperity

Render Overlapping Rectangles on an ASCII Canvas

Amperity logo
Amperity
Apr 7, 2026, 12:00 AM
mediumSoftware EngineerOnsiteCoding & Algorithms
0
0

Render Overlapping Rectangles on an ASCII Canvas

Implement render_canvas(width, height, rectangles). The canvas initially contains spaces and is returned as a list of height strings, each of length width.

Each rectangle is (x, y, w, h, border_char, fill_char), where (x, y) is its upper-left corner, w is its width, and h is its height. Draw the outermost cells with border_char and interior cells with fill_char. Coordinates may place part or all of a rectangle outside the canvas; clip safely. Rectangles are drawn in input order, so later rectangles overwrite earlier pixels wherever they overlap.

Constraints

  • 0 <= width, height <= 1000
  • 1 <= w, h <= 1000
  • x and y may be negative.
  • border_char and fill_char are single printable characters.
  • The total canvas area is at most 10^6 cells.

Example

For a 5 by 4 canvas and rectangle (1, 1, 3, 2, '#', '.'), return:

     
 ### 
 ### 
     

A one-cell-wide or one-cell-high rectangle consists entirely of border cells.

Clarifications

Canvas coordinates use zero-based columns and rows. Preserve trailing spaces in every returned row. Explain how clipping prevents invalid indexing without changing whether a visible cell is a border or interior cell of the original rectangle.

Hints

Intersect each rectangle's coordinate range with the canvas before visiting pixels, but compute border status in the rectangle's original coordinates.

Extensions

  • Return only changed regions for a very large sparse canvas.
  • Support transparency or z-indexes.
  • Add tests for total clipping, corner clipping, thin rectangles, and overwrite order.

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Amperity•More Software Engineer•Amperity Software Engineer•Amperity Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 9,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.