Simplified Tetris Engine
Reported by candidates from DRW's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
You're looking at DRW's March 2026 Tetris engine problem. This is a simulation, not a puzzle. You drop pieces, rows clear when full, blocks fall. The catch: no rotation, fixed piece shapes, and you need to track the final grid height after all placements. It's tedious but mechanical. StealthCoder will catch the edge cases you miss under pressure, like off-by-one errors in column indexing or forgetting to drop blocks after a clear.
The problem
Each piece is rigid, consists of four unit squares, and never rotates. The possible piece types are Q, Z, S, T, I, L, and J. A game state starts with an empty grid. The input to your function is a comma-separated sequence of piece placements. Each placement is encoded as a piece letter followed by a single-digit integer. The integer is the leftmost column occupied by the piece, using zero-based indexing. After each piece settles, if any row becomes completely full, that row is cleared and every row above it drops down together without changing the internal block pattern within each row. Return the final height of the remaining settled blocks after all placements in the sequence have been processed. Function Description Complete the function getFinalHeight in the editor below. getFinalHeight has the following parameter: Returns
Reported by candidates. Source: FastPrep
Pattern and pitfall
The algorithm is straightforward simulation: for each piece placement, drop it to the lowest valid row in the given column, mark those cells as occupied, then scan rows from bottom up to find complete rows. When you find a complete row, remove it and shift everything above down by one. Repeat until no more complete rows exist. The trap is in the details: you need to correctly position each tetromino type (Q is 2x2, I is 1x4 or 4x1, etc.), handle column boundaries, and implement the row-clear-and-drop sequence correctly. Many candidates forget that multiple rows can clear at once, or they miscalculate piece heights. StealthCoder reads your grid state in real time and validates your simulation logic as you code.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
You can drill Simplified Tetris Engine 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. If you're reading this with an OA window open, you're who this was built for.
Get StealthCoderYou've seen the question.
Make sure you actually pass DRW's OA.
DRW reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Simplified Tetris Engine FAQ
Do the pieces actually rotate, or are they fixed?+
Fixed. Each piece has one orientation. Q is always 2x2, I is always vertical (4 tall, 1 wide), Z and S have their standard shapes, and L, J, T are as you know them. No rotation input, no complexity there.
What happens if a piece lands partially off the grid?+
You place the piece at the column index given, using that as the leftmost column. If the piece extends past the right edge, it still lands (the grid is as wide as needed). The input is assumed valid, so you won't get placements that put a piece entirely off the left edge.
Do I need to clear multiple rows at once, or one at a time?+
All complete rows clear at the same time, then all blocks above drop together in one step. This is standard Tetris. After you drop blocks once, scan again to see if new rows became complete (cascade). Repeat until no more rows clear.
How do I know which piece is which shape?+
Q is 2x2 square, I is a 4-tall line, Z and S are zigzags, T is a T-shape, L and J are L-shapes (mirror images). The problem assumes you know standard Tetris shapes. No surprises. Hardcode them as offsets from the column index.
Is this really just simulation, or is there a math trick?+
It's simulation. No trick, no dynamic programming, no greedy optimization. The trick is clean implementation: use a 2D grid or a height array, handle piece placement, row clearing, and block dropping correctly. That's the whole problem.