FastPrepLayered ASCII Canvas Command Processor
Problems/Layered ASCII Canvas Command Processor

Layered ASCII Canvas Command Processor

Asana logoAsana● HardFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Asana full-time onsite interview. The report describes a fixed 10-by-6 ASCII canvas with layers. The commands draw rectangles, erase an area for good, drag and drop, bring to front, and print. The report leaves out the field for the drawing character, how commands are written, what happens with an invalid selection, and how printing is written out. We chose those. Our version is about 86% the same as the reported question.

Given commands, run them in order on a canvas with width 10 and height 6, and return the printed snapshots. Coordinates start at zero: x grows from left to right and y grows from top to bottom. The background character is ..

The commands are:

  • DRAW_RECTANGLE left top right bottom ch: draw a filled rectangle, edges included, using the single uppercase character ch. A new rectangle goes in front of all others.
  • ERASE_AREA left top right bottom: erase for good every rectangle cell that currently lies inside this area, edges included. Hidden cells are erased too. A rectangle keeps its erased cells as holes that move with it when it is dragged later.
  • DRAG_AND_DROP fromX fromY toX toY: pick the frontmost rectangle that has a non-erased cell at the source point. Shift that rectangle so the picked cell lands on the destination point. It keeps its layer position. If no rectangle shows at the source, do nothing.
  • BRING_TO_FRONT x y: move the frontmost rectangle that has a non-erased cell at that point in front of all others. If no rectangle shows there, do nothing.
  • PRINT_CANVAS: add one snapshot of the current canvas to the answer.

A snapshot joins the six rows, top to bottom, with /. Each cell shows the character of the frontmost rectangle whose cell there is not erased, or . if there is none. Return the snapshots in PRINT_CANVAS order.

Function

processCanvas(commands: String[]) → String[]

Examples

Example 1

commands = ["DRAW_RECTANGLE 1 1 4 3 A","PRINT_CANVAS","DRAW_RECTANGLE 3 0 6 2 B","PRINT_CANVAS","ERASE_AREA 4 1 5 1","PRINT_CANVAS"]return = ["........../.AAAA...../.AAAA...../.AAAA...../........../..........","...BBBB.../.AABBBB.../.AABBBB.../.AAAA...../........../..........","...BBBB.../.AAB..B.../.AABBBB.../.AAAA...../........../.........."]

Rectangle B is drawn over part of A. Erasing columns 4 through 5 on row 1 removes the B cells there and the hidden A cell below B.

Example 2

commands = ["DRAW_RECTANGLE 1 1 2 2 X","DRAG_AND_DROP 1 1 5 3","PRINT_CANVAS","ERASE_AREA 5 3 5 3","DRAG_AND_DROP 6 4 7 5","PRINT_CANVAS"]return = ["........../........../........../.....XX.../.....XX.../..........","........../........../........../........../.......X../......XX.."]

The first drag shifts X right by 4 and down by 2. After its top-left cell is erased, the second drag grabs its bottom-right cell and moves the shape, hole included.

Constraints

  • 1 <= commands.length <= 1000.
  • Every command has exactly the syntax shown above and integer coordinates within the canvas.
  • Every drawn rectangle satisfies 0 <= left <= right < 10 and 0 <= top <= bottom < 6.
  • Every drag that selects a rectangle keeps that rectangle fully inside the canvas after translation.
  • Every ch is one uppercase English letter.
  • At most 200 rectangles are created.

More Asana Onsite Interview questions

  • Cats, Rabbits, and Snails Board GameONSITE INTERVIEW · Seen Aug 2026
  • K Closest Points to a TargetONSITE INTERVIEW · Seen Aug 2026

Similar questions at other companies

  • Ultimate Tic-Tac-Toe Move SimulatorHebbia · PHONE SCREEN
  • Machine Message RouterOpenAI · PHONE SCREENOpenAI interview questions
  • Randomized Collection with Duplicate ValuesOkta · ONSITE INTERVIEWOkta interview questions
  • Cache Shared Image Pipeline PrefixesAnthropic · ONSITE INTERVIEWAnthropic interview questions
  • Hybrid Run-Length and Bit-Packing EncoderDatabricks · ONSITE INTERVIEWDatabricks interview questions
  • Transformer Attention and SwiGLU Forward PassGoogle · ONSITE INTERVIEWGoogle interview questions
  • In-Memory SQL with CSV InitializationMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
  • Spiral MatrixAthenahealth · ONSITE INTERVIEW
  • Query Log MatchDatadog · PHONE SCREEN · ONSITE INTERVIEWDatadog interview questions
  • Random Dasher Set OperationsDoorDash · ONSITE INTERVIEWDoorDash interview questions
See Asana hiring insights
Saved
class Solution {
    public String[] processCanvas(String[] commands) {
        // write your code here
    }
}
Checking account…