Reported January 2022
Ripplingsimulation

Layered Rectangle Canvas

Reported by candidates from Rippling's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Rippling OA. Under 2s to a working solution.
Founder's read

Rippling's January 2022 OA hands you a layered canvas and a pile of DRAW and MOVE commands. The naive instinct is to paint cells as you go and erase on move. That breaks the second a lower rectangle should reappear. It's a simulation problem on a small grid, and the trick is deciding what you store. If the OA invite is in your inbox, read this first. StealthCoder is the backup if your mind goes blank mid-assessment, but the idea here is short enough to hold in your head.

The problem

You are given a rectangular character canvas with rows rows and cols columns. Every uncovered cell initially contains '.'.
Process each string in commands from left to right. Coordinates are zero-indexed, and every command has one of these forms:
DRAW id top left height width ch creates a filled rectangle with a unique identifier id. Its top-left cell is (top, left), it occupies height rows and width columns, and every occupied cell contributes the uppercase character ch. A newly drawn rectangle is placed above every rectangle that already exists.
MOVE id rowDelta colDelta translates the existing rectangle id by adding rowDelta to its top coordinate and colDelta to its left coordinate. Moving a rectangle does not change its layer position.
At any cell covered by multiple rectangles, the topmost rectangle contributes the visible character. When a rectangle moves away, any lower rectangle underneath it becomes visible again.
Return the final canvas as an array of rows strings, each of length cols.

Function
renderRectangleCanvas(rows: int, cols: int, commands: String[]) → String[]

Examples
Example 1
rows = 4
cols = 7
commands = ["DRAW back 0 0 3 4 A","DRAW front 1 2 2 4 B"]
return = ["AAAA...","AABBBB.","AABBBB.","......."]
The rectangle front was drawn later, so its 'B' cells cover the overlapping portion of back.
Example 2
rows = 4
cols = 6
commands = ["DRAW low 0 0 2 3 L","DRAW high 1 1 2 3 H","MOVE low 1 2"]
return = ["......",".HHHL.",".HHHL.","......"]
Moving low preserves its original lower layer. Its cells become visible only where high does not cover them.
Example 3
rows = 5
cols = 7
commands = ["DRAW base 1 1 3 5 X","DRAW top 2 2 2 2 O","MOVE top -1 3"]
return = [".......",".XXXXOO",".XXXXOO",".XXXXX.","......."]
The upper rectangle moves to columns 5 and 6. Its old cells reveal base, while its new overlap at column 5 remains visible as 'O'.

Constraints
1 <= rows, cols <= 50.
1 <= commands.length <= 1000.
At most 200 rectangles are drawn.
Every id is a nonempty alphanumeric string; each DRAW uses a new ID, and each MOVE names an existing ID.
Each ch is one uppercase English letter.
Every rectangle has positive height and width, and every draw or move leaves the complete rectangle inside the canvas.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Don't paint as you go. Store each rectangle as a record: id, top, left, height, width, char, plus its layer order. Keep them in a list in draw order, with a map from id to record. DRAW appends. MOVE just edits top and left, and the layer position never changes. Only at the end do you render. Start with a grid of dots, then loop through rectangles from oldest to newest and overwrite every cell they cover. The last write wins, so the topmost rectangle shows. That handles the reveal case automatically, since a moved rectangle simply stops covering old cells. The pitfall is erasing on MOVE, which loses what was underneath. Parsing is the other trap: split each command by spaces and convert the numbers, including negative deltas. Constraints are tiny, at most 200 rectangles on a 50 by 50 grid, so brute force is fine. StealthCoder is there on the live OA if you freeze on the render order.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Layered Rectangle Canvas cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Rippling's OA.

Rippling reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Layered Rectangle Canvas FAQ

What's the trick in the Rippling layered canvas problem?+

Don't mutate the grid during commands. Store rectangles with their draw order, update coordinates on MOVE, and render once at the end by painting oldest to newest. The newest write wins, which gives you correct layering and automatic reveal of lower rectangles.

How hard is this OA really?+

It's easier than it looks. There's no clever algorithm, just careful state handling and parsing. The hard part is resisting the urge to erase and repaint incrementally. If you separate the data from the rendering, it's maybe thirty lines.

Does MOVE change which rectangle is on top?+

No. The problem says moving preserves layer position. A rectangle drawn early stays low even after it moves, so it can slide out from under others or end up beneath rectangles it didn't overlap before. Your draw-order list never gets reordered.

Is brute force fast enough here?+

Yes. With at most 200 rectangles on a 50 by 50 canvas, rendering costs at most 200 times 2500 cell writes. Commands are capped at 1000, and each one is constant time. You don't need any spatial structure or optimization.

How do I prepare for this in 48 hours?+

Practice grid simulation problems where you keep state as objects and render at the end. Write a command parser that handles negative integers. Test your solution against all three examples by hand, especially the MOVE cases that reveal a lower layer.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Rippling.

OA at Rippling?
Invisible during screen share
Get it